您现在的位置是:首页 > 电脑技术查询 > web开发

javascript的有关问题

编辑:chaxungu时间:2022-10-02 23:14:39分类:web开发

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]
}