日期:2014-05-16  浏览次数:20384 次

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