需要了解寄生蟲遺傳實際上做了什麼。需要了解Javascript寄生遺傳
我提到這個鏈接:Parasitic Inheritance in javascript
我需要了解一下這個例子做:
Shape = {name: 'Shape'};
Shape.prototype.toString = function()
{
return this.name;
};
function Rectangle(width, height) {
var rect;
P = function() {};
P.prototype = Shape;
rect = new P();
rect.width = width;
rect.height = height;
return rect;
}
第二個例子能正常工作,但我需要知道「哪裏寄生繼承進入圖片?「
var Person = function(name, age)
{
this.name = name;
this.age = age;
};
var Employee = function(name, age, group)
{
var e = new Person(name, age);
e.group = group;
return e;
};
var testname= new Employee('ABC', 30, 'Developer');
謝謝。
它不起作用。 – thefourtheye
但鏈接使用這個例子,我無法理解邏輯。 –
嘗試在某處執行它。 – thefourtheye