DOM操作では以下のように setAttribute してすぐメソッドを呼べない
elm.setAttribute( "name", "value" ).getAttribute( "name" );
なので、メソッド名に"_"を付けて実行するとthisを返す拡張をしてやると
Object.prototype.__noSuchMethod__=function(methodName,argsArray){
if(methodName.match(/^_[^_]/)){
var method=methodName.substr(1);
if(this[method]){
this[method].apply(this,argsArray);
return this;
}
}
throw new TypeError(methodName+" is not a function");
};
elm._setAttribute( "name", "value" ).getAttribute( "name" );
if(methodName.match(/^_[^_]/)){
var method=methodName.substr(1);
if(this[method]){
this[method].apply(this,argsArray);
return this;
}
}
throw new TypeError(methodName+" is not a function");
};
elm._setAttribute( "name", "value" ).getAttribute( "name" );
あれ?
ネタのつもりが結構便利かも。
これってどうなの?
教えてえらい人!
ネタのつもりが結構便利かも。
これってどうなの?
教えてえらい人!