This line here:
constructor.applay(ist, Array.prototype.slice.call(arguments, 1)
Typo in apply ;)
You do need to invoke the constructor and this line is actually correct, but you can do less. Think about what apply() expects as arguments and what you have available to you.
@OlgaMaraeva you forgot to create a Person function constructor that’s why it says «Person is undefined»
I also corrected a line where you use prototype property for object. You should use instead proto property if you want to set its prototype.
You can see it here: http://jsfiddle.net/0tLsn27x/1/
@OlgaMaraeva you’re welcome:) About person constructor. It’s not NEW’s responsibility to create a function constructor. When you use NEW or even original new keyword, function constructor had to be created before you use it with new.
Just try this code var obj = new Person()
in console.
This code won’t work because Person isn’t defined. The same thing with our NEW function.
Thus, you should manually create function constructor and then use it with NEW or original new keyword.
Example:
function Person(name){this.name = name}
var justin = new Person('Justin')
var david = NEW(Person,['David'])
About proto
property. You’re absolutely right. It’s deprecated and ist.prototype = Object. create(constructor.prototype)
is a better option.
I used proto
property just to emphasize that proto
and prototype
are completly different things.
thing.__proto__
would just be like doing thing.foo