Prototypes in Javascript

Asked

Viewed 47 times

0

What are the following methods for:

  • hasOwnProperty();
  • getPrototypeOf();

And what is its function in the code below:

var carro = {};
carro.modelo = 'Celta';
carro.marca = 'Chevrolet';
carro.hasOwnProperty('modelo');
Object.getPrototypeOf(carro);

1 answer

0


To learn more about read here and here.

var carro = {};
carro.modelo = 'Celta';
carro.marca = 'Chevrolet';
console.log(carro.hasOwnProperty('modelo')); // retorna um boolean indicando se o objeto possui a propriedade especificada.
console.log(Object.getPrototypeOf('carro')); // retorna o prototype (isto é, o valor da propriedade interna [[Prototype]]) do objeto especificado.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.