建立自定义对象的方法
function Person( ) { }
Person.prototype={
constructor:Person,
name:"Jack",
age:100,
sayHi:function ( ) {
alert("hello"+this.name);
}
}; var p1=new Person( );
p1.sayHi();扩展内置对象(String)的方法
String.prototype={ constructor:this, run:function () {
alert("success!");
}
}; var n="####";
n.run();后面的constructor属性不指向String对象(前面的constructor属性指向Person对象),这是为什么呢?
互换的青春
一只甜甜圈
随时随地看视频慕课网APP
相关分类