Javascript中this、prototype、constructor的理解
2012-05-31 19:59
591 查看
this:
1、this表示当前对象2、如果在全局作用范围内使用this,则指代当前页面对象window
3、如果在函数中使用this,则this指代什么是根据运行时此函数在什么对象上被调用
4、可以使用apply和call两个全局方法来改变函数中this的具体指向。
prototype:
1、prototype是一个JavaScript对象;2、每个函数都有一个默认的prototype属性;
3、通过prototype我们可以扩展Javascript的内建对象
利用prototype扩展对象的经典模式(构造函数+原型):
function HelloKitty(id,name){
this.id = id;
this.name = name;
}
HelloKitty.prototype.donaldDuck = function(){
alert(this.id+”-----”+this.name);
}
var helloKitty = new HelloKitty(mickey,mouse);
helloKitty.donaldDuck();
constructor:
1、constructor始终指向创建当前对象的构造(初始化)函数。2、每个函数都有一个默认的属性prototype,而这个prototype的constructor默认指向这个函数
相关文章推荐
- Javascript中this、prototype、constructor的理解
- Javascript中this、prototype、constructor的理解
- Javascript中this、prototype、constructor的理解
- Javascript中this、prototype、constructor的理解
- Javascript中this、prototype、constructor的理解
- Javascript中this、prototype、constructor的理解
- javascript中的this与prototype,原型理解
- JavaScript——this、constructor、prototype
- 深入理解JavaScript原型:prototype,__proto__和constructor
- JavaScript中几个重要的属性(this、constructor、prototype)
- JavaScript中几个重要的属性(this、constructor、prototype)介绍
- javascript中的this,constructor ,prototype
- javascript Prototype constructor的理解(一)
- javascript Prototype constructor的理解
- JavaScript中几个重要的属性(this、constructor、prototype)介绍
- 彻底搞清javascript中this, constructor, prototype
- 关于JavaScript的prototype、__proto__、constructor、this
- JavaScript中几个重要的属性(this、constructor、prototype)介绍
- JavaScript的原型链继承__propt__、prototype、constructor的理解、以及他们之间相互的关系。
- 转载 在Javascript面向对象的编程中我们常常会见到这三个关键字:this、prototype、constructor。