A
A
Anton Titov2016-08-01 20:10:26
JavaScript
Anton Titov, 2016-08-01 20:10:26

Why doesn't the constructor property inherit?

There is a constructor:

function Manipulate (){
      this.btn = 1 ;
      this.ul  = 2;
       };

There is a method:
Manipulate.prototype.test = () => this.btn +this.ul;

There is inheritance:
const add = Object.create(Manipulate);
Why does the check say that add does not inherit the test method?
console.log(add.hasOwnProperty('test')); //false

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Sergey, 2016-08-01
Protko @Fesor

https://developer.mozilla.org/en-US/docs/Web/JavaS...

D
Dmitry Belyaev, 2016-08-01
@bingo347

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

A
A person from Kazakhstan, 2016-08-01
@LenovoId

in brackets id is written in quotes like

A
Anton Titov, 2016-08-01
@AntonTitovI

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 question

Ask a Question

731 491 924 answers to any question