Appearance
实例方法 
hasOwnProperty() 
TIP
方法返回一个布尔值,表示对象自有属性(而不是继承来的属性)中是否具有指定的属性
javascript
const object1 = {};
object1.property1 = 42;
console.log(object1.hasOwnProperty('property1'));
// Expected output: true
console.log(object1.hasOwnProperty('toString'));
// Expected output: false
console.log(object1.hasOwnProperty('hasOwnProperty'));
// Expected output: falseisPrototypeOf() 
TIP
方法用于检查一个对象是否存在于另一个对象的原型链中
javascript
function Foo() {}
function Bar() {}
Bar.prototype = Object.create(Foo.prototype);
const bar = new Bar();
console.log(Foo.prototype.isPrototypeOf(bar));
// Expected output: true
console.log(Bar.prototype.isPrototypeOf(bar));
// Expected output: truepropertyIsEnumerable() 
TIP
方法返回一个布尔值,表示指定的属性是否是对象的可枚举自有属性
javascript
const object1 = {};
const array1 = [];
object1.property1 = 42;
array1[0] = 42;
console.log(object1.propertyIsEnumerable('property1'));
// Expected output: true
console.log(array1.propertyIsEnumerable(0));
// Expected output: true
console.log(array1.propertyIsEnumerable('length'));
// Expected output: falsetoLocaleString() 
TIP
方法返回一个表示对象的字符串。该方法旨在由派生对象重写,以达到其特定于语言环境的目的
javascript
const date1 = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
console.log(date1.toLocaleString('ar-EG'));
// Expected output: "٢٠/١٢/٢٠١٢ ٤:٠٠:٠٠ ص"
const number1 = 123456.789;
console.log(number1.toLocaleString('de-DE'));
// Expected output: "123.456,789"toString() 
TIP
方法返回一个表示该对象的字符串。该方法旨在重写(自定义)派生类对象的类型转换的逻辑
javascript
function Dog(name) {
  this.name = name;
}
const dog1 = new Dog('Gabby');
Dog.prototype.toString = function dogToString() {
  return `${this.name}`;
};
console.log(dog1.toString());
// Expected output: "Gabby"valueOf() 
TIP
方法将 this 值转换成对象。该方法旨在被派生对象重写,以实现自定义类型转换逻辑
javascript
function MyNumberType(n) {
  this.number = n;
}
MyNumberType.prototype.valueOf = function () {
  return this.number;
};
const object1 = new MyNumberType(4);
console.log(object1 + 3);
// Expected output: 7