Answer the question
In order to leave comments, you need to log in
Why doesn't the constructor property inherit?
There is a constructor:
function Manipulate (){
this.btn = 1 ;
this.ul = 2;
};
Manipulate.prototype.test = () => this.btn +this.ul;
const add = Object.create(Manipulate);
console.log(add.hasOwnProperty('test')); //false
Answer the question
In order to leave comments, you need to log in
First, Object.create creates an object from a prototype without calling a constructor, and you need to pass a prototype to it
. const add = Object.create(Manipulate.prototype);
With a constructor call, you need to write like this: const add = new Manipulate('id1', 'id2');
I will add that the arrow function does not have its own context, its this is from the closure, you need a full-fledged function or object method
It's true. The quotes will be in the parameter of the add function. The question is, why does the check say that add does not inherit test? Right now I'll edit to be more abstract.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question