Matt
0
Q:

hasOwnProperty.call js

var person = {	
  	"first_name": "Bob",
	"last_name": "Dylan"
};
person.hasOwnProperty('first_name'); //returns true
person.hasOwnProperty('age'); //returns false
7
var foo = {
  hasOwnProperty: function() {
    return false;
  },
  bar: 'I belong to foo'
};
0
var foo = {
  hasOwnProperty: function() {
    return false;
  },
  bar: 'Here be dragons'
};

foo.hasOwnProperty('bar'); // always returns false

// Use another Object's hasOwnProperty
// and call it with 'this' set to foo
({}).hasOwnProperty.call(foo, 'bar'); // true

// It's also possible to use the hasOwnProperty property
// from the Object prototype for this purpose
Object.prototype.hasOwnProperty.call(foo, 'bar'); // true
0

New to Communities?

Join the community