JS實現self的resend_javascript技巧
來源:懂視網
責編:小采
時間:2020-11-27 20:54:19
JS實現self的resend_javascript技巧
JS實現self的resend_javascript技巧:ECMA V5定義了一個期待已久的方法:Object.getPrototypeOf,它可以無視型別信息得到某對象的原型([[prototype]]),基于此,我們可以構造出一個resend:(請用Chrome 5、IE9預覽第三版測試) 代碼如下: obj.resend = function()
導讀JS實現self的resend_javascript技巧:ECMA V5定義了一個期待已久的方法:Object.getPrototypeOf,它可以無視型別信息得到某對象的原型([[prototype]]),基于此,我們可以構造出一個resend:(請用Chrome 5、IE9預覽第三版測試) 代碼如下: obj.resend = function()

ECMA V5定義了一個期待已久的方法:Object.getPrototypeOf,它可以無視型別信息得到某對象的原型([[prototype]]),基于此,我們可以構造出一個resend:(請用Chrome 5、IE9預覽第三版測試)
代碼如下:
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;
}
}()
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
JS實現self的resend_javascript技巧
JS實現self的resend_javascript技巧:ECMA V5定義了一個期待已久的方法:Object.getPrototypeOf,它可以無視型別信息得到某對象的原型([[prototype]]),基于此,我們可以構造出一個resend:(請用Chrome 5、IE9預覽第三版測試) 代碼如下: obj.resend = function()