读书人

this用法的有关问题

发布时间: 2012-03-21 13:33:15 作者: rapoo

this用法的问题
function Car(color){
this.color = color;
}
var new_car= new Car( "1 ");
alert(new_car.color);


为什么属性就可以
方法就不可以呢

function Car(){
this.dd() = function(){alert( '33 ');};
}
var new_car= new Car();
new_car.dd();

[解决办法]
this.dd() = function(){alert( '33 ');};
---> > >
this.dd = function(){alert( '33 ');};
[解决办法]
this.add = function(){
alert( "kendo ") ;
}

读书人网 >JavaScript

热点推荐