欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JS實(shí)現(xiàn)self的resend

 更新時(shí)間:2010年07月22日 01:00:42   作者:  
self中resend是調(diào)用“基類方法”的原語(yǔ),它會(huì)把當(dāng)前接收到的消息原樣發(fā)送給其原型(parent*)。在ECMA-v5時(shí)代,我們終于可以做出這個(gè)偉大的東西了。
ECMA V5定義了一個(gè)期待已久的方法:Object.getPrototypeOf,它可以無(wú)視型別信息得到某對(duì)象的原型([[prototype]]),基于此,我們可以構(gòu)造出一個(gè)resend:(請(qǐng)用Chrome 5、IE9預(yù)覽第三版測(cè)試)
復(fù)制代碼 代碼如下:

obj.resend = function() {
var pof = Object.getPrototypeOf;
var has = function() {......} // hasOwnProperty的封裝
var make = function(obj, old) {
return function(name, args) {
var step = pof(obj),
r;
while (step && !has(step, name)) step = pof(step);
if (!step) throw new Error('Unable to resend: method missing');

var foundMethod = step[name];
var backup = arguments.callee;
this.resend = make(this, backup);
r = foundMethod.apply(this, Array.prototype.slice.call(arguments, 1));
this.resend = old;
return r
}
};

return function(name, args__) {
var rv;
var old = this.resend;
this.resend = make(this, old);
rv = this.resend.apply(this, arguments);
this.resend = original;
return rv;
}
}()

相關(guān)文章

  • javascript簡(jiǎn)單拖拽實(shí)現(xiàn)代碼(鼠標(biāo)事件 mousedown mousemove mouseup)

    javascript簡(jiǎn)單拖拽實(shí)現(xiàn)代碼(鼠標(biāo)事件 mousedown mousemove mouseup)

    javascript簡(jiǎn)單拖拽,簡(jiǎn)單拖拽實(shí)現(xiàn)
    2012-05-05
  • 最新評(píng)論