fix: converted single to triple backticks4 (#36231)

This commit is contained in:
Randell Dawson
2019-06-20 14:07:46 -07:00
committed by Tom
parent 0011f254c1
commit 926ddea5b0
75 changed files with 886 additions and 782 deletions

View File

@@ -8,30 +8,32 @@ localeTitle: إضافة طرق بعد الوراثة
تمامًا كما في المثال التالي ، يجب إنشاء مثيل جديد لكائن - `Dog` - ويجب تعيين `prototype` .
`function Bird() { }
Bird.prototype = Object.create(Animal.prototype);
Bird.prototype.constructor = Bird;
`
```javascript
function Bird() { }
Bird.prototype = Object.create(Animal.prototype);
Bird.prototype.constructor = Bird;
```
ثم يجب إضافة وظيفة جديدة - `bark()` - إلى نموذج الكلب.
### حل
`function Animal() { }
Animal.prototype.eat = function() { console.log("nom nom nom"); };
function Dog() { }
// Add your code below this line
Dog.prototype = Object.create(Animal.prototype);
Dog.prototype.constructor = Dog;
Dog.prototype.bark = function() {
console.log("Woof woof!");
};
// Add your code above this line
let beagle = new Dog();
beagle.eat(); // Should print "nom nom nom"
beagle.bark(); // Should print "Woof!"
`
```javascript
function Animal() { }
Animal.prototype.eat = function() { console.log("nom nom nom"); };
function Dog() { }
// Add your code below this line
Dog.prototype = Object.create(Animal.prototype);
Dog.prototype.constructor = Dog;
Dog.prototype.bark = function() {
console.log("Woof woof!");
};
// Add your code above this line
let beagle = new Dog();
beagle.eat(); // Should print "nom nom nom"
beagle.bark(); // Should print "Woof!"
```

View File

@@ -28,20 +28,21 @@ localeTitle: تغيير النموذج إلى كائن جديد
## الحل 1:
`function Dog(name) {
this.name = name;
}
Dog.prototype = {
// Add your code below this line
numLegs: 2,
eat: function(){
console.log('nom nom nom');
},
describe: function(){
console.log("My name is " + this.name);
}
}
`
```javascript
function Dog(name) {
this.name = name;
}
Dog.prototype = {
// Add your code below this line
numLegs: 2,
eat: function(){
console.log('nom nom nom');
},
describe: function(){
console.log("My name is " + this.name);
}
}
```
## شرح الشفرة:
@@ -51,21 +52,22 @@ localeTitle: تغيير النموذج إلى كائن جديد
## الحل 2:
`function Dog(name) {
this.name = name;
}
Dog.prototype = {
// Add your code below this line
numLegs: 2,
eat(){
console.log('nom nom nom');
},
describe(){
console.log("My name is " + this.name);
}
};
`
```javascript
function Dog(name) {
this.name = name;
}
Dog.prototype = {
// Add your code below this line
numLegs: 2,
eat(){
console.log('nom nom nom');
},
describe(){
console.log("My name is " + this.name);
}
};
```
## شرح الشفرة:

View File

@@ -10,8 +10,9 @@ localeTitle: قم بإنشاء كائن JavaScript أساسي
### حل:
`let dog = {
name: "George",
numLegs: 4
};
`
```javascript
let dog = {
name: "George",
numLegs: 4
};
```

View File

@@ -19,13 +19,14 @@ localeTitle: إنشاء طريقة على كائن
### حل:
`let dog = {
name: "Spot",
numLegs: 4,
sayLegs: function() {
return "This dog has " + dog.numLegs + " legs.";
}
};
dog.sayLegs();
`
```javascript
let dog = {
name: "Spot",
numLegs: 4,
sayLegs: function() {
return "This dog has " + dog.numLegs + " legs.";
}
};
dog.sayLegs();
```

View File

@@ -10,9 +10,10 @@ localeTitle: تحديد وظيفة منشئ
### حل:
`function Dog() {
this.name = "Geogre",
this.color = "White",
this.numLegs = 4;
}
`
```javascript
function Dog() {
this.name = "Geogre",
this.color = "White",
this.numLegs = 4;
}
```

View File

@@ -10,10 +10,11 @@ localeTitle: تمديد البنائين لتلقي الحجج
### حل:
`function Dog(name, color) {
this.name = name;
this.color = color;
this.numLegs = 4;
}
let terrier = new Dog("George","White");
`
```javascript
function Dog(name, color) {
this.name = name;
this.color = color;
this.numLegs = 4;
}
let terrier = new Dog("George","White");
```

View File

@@ -12,8 +12,9 @@ localeTitle: وراثة السلوكيات من Supertype
السماح للحيوان = Object.create (Animal.prototype) ؛
`### Solution
`
```
### Solution
```
جافا سكريبت

View File

@@ -10,24 +10,25 @@ localeTitle: تكرار جميع الممتلكات
### حل
`function Dog(name) {
this.name = name;
}
Dog.prototype.numLegs = 4;
let beagle = new Dog("Snoopy");
let ownProps = [];
let prototypeProps = [];
// Add your code below this line
for (let property in beagle) {
if(Dog.hasOwnProperty(property)) {
ownProps.push(property)
}
else {
prototypeProps.push(property)
}
}
`
```javascript
function Dog(name) {
this.name = name;
}
Dog.prototype.numLegs = 4;
let beagle = new Dog("Snoopy");
let ownProps = [];
let prototypeProps = [];
// Add your code below this line
for (let property in beagle) {
if(Dog.hasOwnProperty(property)) {
ownProps.push(property)
}
else {
prototypeProps.push(property)
}
}
```

View File

@@ -10,11 +10,12 @@ localeTitle: جعل رمز أكثر قابلة لإعادة الاستخدام
### حل:
`let dog = {
name: "Spot",
numLegs: 4,
sayLegs: function() {return "This dog has " + this.numLegs + " legs.";}
};
dog.sayLegs();
`
```javascript
let dog = {
name: "Spot",
numLegs: 4,
sayLegs: function() {return "This dog has " + this.numLegs + " legs.";}
};
dog.sayLegs();
```

View File

@@ -6,7 +6,8 @@ localeTitle: تجاوز الأساليب الموروثة
# حل
`Penguin.prototype.fly = function() {
return "Alas, this is a flightless bird.";
};
`
```javascript
Penguin.prototype.fly = function() {
return "Alas, this is a flightless bird.";
};
```

View File

@@ -8,16 +8,17 @@ localeTitle: تذكر تعيين الخاصية منشئ عند تغيير "ال
# حل
`Dog.prototype = {
constructor: Dog, // Solution
numLegs: 2,
eat: function() {
console.log("nom nom nom");
},
describe: function() {
console.log("My name is " + this.name);
}
};
`
```javascript
Dog.prototype = {
constructor: Dog, // Solution
numLegs: 2,
eat: function() {
console.log("nom nom nom");
},
describe: function() {
console.log("My name is " + this.name);
}
};
```

View File

@@ -8,22 +8,24 @@ localeTitle: إعادة تعيين منشئ Conherrated الخاصية
تمت برمجة كائنات `duck` `beagle` لترث خصائص `supertypes` . للكتابة فوق هذين السطرين من التعليمات البرمجية يجب أن تتم كتابتها لتعيين المنشئين إلى المنشئين المطلوبين `Bird` و `Dog` . يوضح التعليمة البرمجية التالية كيف يمكن تحقيق ذلك.
`Bird.prototype.constructor = Bird;
`
```javascript
Bird.prototype.constructor = Bird;
```
### حل
`function Animal() { }
function Bird() { }
function Dog() { }
Bird.prototype = Object.create(Animal.prototype);
Dog.prototype = Object.create(Animal.prototype);
// Add your code below this line
Bird.prototype.constructor = Bird;
Dog.prototype.constructor = Dog;
let duck = new Bird();
let beagle = new Dog();
`
```javascript
function Animal() { }
function Bird() { }
function Dog() { }
Bird.prototype = Object.create(Animal.prototype);
Dog.prototype = Object.create(Animal.prototype);
// Add your code below this line
Bird.prototype.constructor = Bird;
Dog.prototype.constructor = Dog;
let duck = new Bird();
let beagle = new Dog();
```

View File

@@ -8,25 +8,27 @@ localeTitle: قم بتعيين Prototype الخاص بالطفل إلى مثيل
لا يختلف هذا التحدي عن التحدي الأخير ، حيث يجب عليك إنشاء كائن يرث من النوع `supertype` . فقط هذه المرة سوف يرث `Dog` الفرعي نوع `Animal` الفائق. ببساطة إنشاء مثيل جديد من `Dog.prototype` مثل المثال التالي.
`Bird.prototype = Object.create(Animal.prototype);
`
```javascript
Bird.prototype = Object.create(Animal.prototype);
```
### حل
`function Animal() { }
Animal.prototype = {
constructor: Animal,
eat: function() {
console.log("nom nom nom");
}
};
function Dog() { }
// Add your code below this line
Dog.prototype = Object.create(Animal.prototype);
let beagle = new Dog();
beagle.eat(); // Should print "nom nom nom"
`
```javascript
function Animal() { }
Animal.prototype = {
constructor: Animal,
eat: function() {
console.log("nom nom nom");
}
};
function Dog() { }
// Add your code below this line
Dog.prototype = Object.create(Animal.prototype);
let beagle = new Dog();
beagle.eat(); // Should print "nom nom nom"
```

View File

@@ -12,12 +12,13 @@ localeTitle: فهم خصائص خاصة
### حل:
`let canary = new Bird("Tweety");
let ownProps = [];
// Add your code below this line
for(let property in canary) {
if(canary.hasOwnProperty(property)) {
ownProps.push(property);
}
}
`
```javascript
let canary = new Bird("Tweety");
let ownProps = [];
// Add your code below this line
for(let property in canary) {
if(canary.hasOwnProperty(property)) {
ownProps.push(property);
}
}
```

View File

@@ -10,17 +10,18 @@ localeTitle: فهم خاصية منشئ
### حل
`function Dog(name) {
this.name = name;
}
// Add your code below this line
function joinDogFraternity(candidate) {
if(candidate.constructor === Dog) {
return true;
}
else {
return false;
}
}
`
```javascript
function Dog(name) {
this.name = name;
}
// Add your code below this line
function joinDogFraternity(candidate) {
if(candidate.constructor === Dog) {
return true;
}
else {
return false;
}
}
```

View File

@@ -10,7 +10,8 @@ localeTitle: فهم تعبير الدالة المستحثة فوراً (IIFE)
### حل
`(function() {
console.log("A cozy nest is ready");
})();
`
```javascript
(function() {
console.log("A cozy nest is ready");
})();
```

View File

@@ -10,11 +10,12 @@ localeTitle: استخدم منشئ لإنشاء كائنات
### حل:
`function Dog() {
this.name = "Rupert";
this.color = "brown";
this.numLegs = 4;
}
// Add your code below this line
let hound = new Dog();
`
```javascript
function Dog() {
this.name = "Rupert";
this.color = "brown";
this.numLegs = 4;
}
// Add your code below this line
let hound = new Dog();
```

View File

@@ -10,22 +10,23 @@ localeTitle: استخدم Mixin لإضافة سلوك شائع بين الكائ
### حل
`let bird = {
name: "Donald",
numLegs: 2
};
let boat = {
name: "Warrior",
type: "race-boat"
};
// Add your code below this line
let glideMixin = function(obj) {
obj.glide = function() {
console.log("Gliding!");
}
};
glideMixin(bird);
glideMixin(boat);
`
```javascript
let bird = {
name: "Donald",
numLegs: 2
};
let boat = {
name: "Warrior",
type: "race-boat"
};
// Add your code below this line
let glideMixin = function(obj) {
obj.glide = function() {
console.log("Gliding!");
}
};
glideMixin(bird);
glideMixin(boat);
```

View File

@@ -8,35 +8,37 @@ localeTitle: استخدم IIFE لإنشاء وحدة نمطية
يجب أن تكون ملفوفة في كلا `Mixin` 's في `funModule` جديدة لذا نقطة بداية esay للتعليق خارج الكود حتى الآن.
`/*let isCuteMixin = function(obj) {
obj.isCute = function() {
return true;
};
};
let singMixin = function(obj) {
obj.sing = function() {
console.log("Singing to an awesome tune");
};
};
*/
`
```javascript
/*let isCuteMixin = function(obj) {
obj.isCute = function() {
return true;
};
};
let singMixin = function(obj) {
obj.sing = function() {
console.log("Singing to an awesome tune");
};
};
*/
```
ثم أدناه ابدأ بكتابة كود `funModule` الجديد. داخل الوحدة النمطية الجديدة ، تحتاج إلى كتابة بيان إرجاع لإرجاع كتل التعليمات البرمجية `Mixin` . ما عليك سوى نسخ كل من الكود الأصلي لكتل `Mixin` إلى كود الوحدة الجديدة ، ولكن تذكر أن تفصل كل من المزيج مع `,`
### حل
`let funModule = (function() {
return {
isCuteMixin: function(obj) {
obj.isCute = function() {
return true;
};
},
singMixin: function(obj) {
obj.sing = function() {
console.log("Singing to an awesome tune");
};
}
}
})();
`
```javascript
let funModule = (function() {
return {
isCuteMixin: function(obj) {
obj.isCute = function() {
return true;
};
},
singMixin: function(obj) {
obj.sing = function() {
console.log("Singing to an awesome tune");
};
}
}
})();
```

View File

@@ -8,23 +8,25 @@ localeTitle: استخدم Dot Notation للوصول إلى خصائص كائن
ستقوم التعليمة البرمجية التالية ببساطة طباعة `property1` من كائن `obj` .
`let obj = {
property1 = 1,
property2 = 2
};
console.log(obj.property1);
`
```javascript
let obj = {
property1 = 1,
property2 = 2
};
console.log(obj.property1);
```
باتباع هذا المنطق ، استخدم عملية `console.log` لطباعة كل من `property1` و `property2` على الشاشة.
### حل:
`let dog = {
name: "Spot",
numLegs: 4
};
// Add your code below this line
console.log(dog.name);
console.log(dog.numLegs);
`
```javascript
let dog = {
name: "Spot",
numLegs: 4
};
// Add your code below this line
console.log(dog.name);
console.log(dog.numLegs);
```

View File

@@ -8,28 +8,29 @@ localeTitle: استخدام الوراثة حتى لا تكرر نفسك
قم بإزالة طريقة "تناول الطعام" من Cat.prototype و Bear.prototype وأضفها إلى Animal.prototype.
`function Cat(name) {
this.name = name;
};
Cat.prototype = {
constructor: Cat
};
function Bear(name) {
this.name = name;
};
Bear.prototype = {
constructor: Bear
};
function Animal() { };
Animal.prototype = {
constructor: Animal,
eat: function() {
console.log("nom nom nom");
}
};
`
```javascript
function Cat(name) {
this.name = name;
};
Cat.prototype = {
constructor: Cat
};
function Bear(name) {
this.name = name;
};
Bear.prototype = {
constructor: Bear
};
function Animal() { };
Animal.prototype = {
constructor: Animal,
eat: function() {
console.log("nom nom nom");
}
};
```

View File

@@ -10,19 +10,21 @@ localeTitle: استخدم خصائص النموذج لتخفيض قانون مك
#### مثال:
`Obj.prototype.newProperty = "New Property!";
`
```javascript
Obj.prototype.newProperty = "New Property!";
```
باستخدام هذا المنطق ، ببساطة إنشاء خاصية `prototype` جديد لـ `numLegs` . يمكن تمرير حالات الاختبار عن طريق استبدال كائن `Bird` بكائن `Dog` في المثال المعطى - `Bird.prototype.numLegs = 2;`
### حل:
`function Dog(name) {
this.name = name;
}
Dog.prototype.numLegs = 4;
// Add your code above this line
let beagle = new Dog("Snoopy");
`
```javascript
function Dog(name) {
this.name = name;
}
Dog.prototype.numLegs = 4;
// Add your code above this line
let beagle = new Dog("Snoopy");
```

View File

@@ -10,20 +10,22 @@ localeTitle: تحقق من Constructor كائن مع instanceof
#### مثال:
`let hound = new Dog();
`
```javascript
let hound = new Dog();
```
تذكر أن تعطي الدالة `House` معلمة لتهيئة عدد الغرف. ثم ببساطة استدعاء العامل `instanceof` للعودة حقيقية على منزلك الجديد.
### حل:
`/* jshint expr: true */
function House(numBedrooms) {
this.numBedrooms = numBedrooms;
}
// Add your code below this line
let myHouse = new House(5);
myHouse instanceof House;
`
```javascript
/* jshint expr: true */
function House(numBedrooms) {
this.numBedrooms = numBedrooms;
}
// Add your code below this line
let myHouse = new House(5);
myHouse instanceof House;
```