读书人

javascript的有关问题

发布时间: 2012-04-07 17:31:52 作者: rapoo

javascript的问题
function b(){
this.c=function (){

}
}
b.prototype.a=funcion(){}

如果我想删除不是在构造函数内定义的方法(比如这里我要删除a),该怎么写?

[解决办法]
var s = new b();
delete s.a;
[解决办法]
简单得很:
b.prototype.a=undefind;

[解决办法]
function b(){
this.c=function (){

}
}
b.prototype.a=function(){}

var s = new b();

for(var k in s){
if( !s.hasOwnProperty(k) && s[k].constructor == Function )delete s[k]
}
[解决办法]

探讨

function b(){
this.c=function (){

}
}
b.prototype.a=function(){}

var s = new b();

for(var k in s){
if( !s.hasOwnProperty(k) && s[k].constructor == Function )delete s[k]
}

读书人网 >JavaScript

热点推荐