Object实例的属性与方法

版权声明:内容多为自言自语,请自行判断有无价值。 https://blog.csdn.net/weixin_41702247/article/details/83211505
function Person(name){
    this.name=name;
}

var tom=new Person('Tom');
Person.prototype.hair=true;

tom.name;   //Tom

tom.hasOwnProperty('hair');   //false
tom.hasOwnProperty('name');   //true

Person.prototype.isPrototypeOf(tom);    //true
tom.constructor===Person;   //true

tom.propertyIsEnumerable('hair');   //false,不可使用for-in枚举
tom.propertyIsEnumerable('name');   //true

tom.toString();     //[object Object]
tom.valueOf();      //Person {name: "tom"}

constructor

hasOwnProperty()

isPrototypeOf()

propertyIsEnumerable()

toLocaleString()

toString()

valueOf()

猜你喜欢

转载自blog.csdn.net/weixin_41702247/article/details/83211505
今日推荐