1var person = {
2 "first_name": "Bob",
3 "last_name": "Dylan"
4};
5person.hasOwnProperty('first_name'); //returns true
6person.hasOwnProperty('age'); //returns false
1var foo = {
2 hasOwnProperty: function() {
3 return false;
4 },
5 bar: 'I belong to foo'
6};
1var foo = {
2 hasOwnProperty: function() {
3 return false;
4 },
5 bar: 'Here be dragons'
6};
7
8foo.hasOwnProperty('bar'); // always returns false
9
10// Use another Object's hasOwnProperty
11// and call it with 'this' set to foo
12({}).hasOwnProperty.call(foo, 'bar'); // true
13
14// It's also possible to use the hasOwnProperty property
15// from the Object prototype for this purpose
16Object.prototype.hasOwnProperty.call(foo, 'bar'); // true