是否有可能得到this
一個函數的caller
在JavaScript 被稱爲有沒有傳遞this
的論據支持IE瀏覽器的方式以及Firefox/Chrome等?得到「本」是一個功能的調用者是在JavaScript調用
例如:
var ob = {
callme: function() {
doSomething();
}
}
ob.callme();
function doSomething() {
alert(doSomething.caller.this === ob); // how can I find the `this` that
// `callme` was called with
// (`ob` in this case) without
// passing `this` to `doSomething`?
}
我開始懷疑它不是,但我想我可能會問,因爲它會成爲我的代碼更短,更易於閱讀。
@stagas:'__parent__'是一個Mozilla擴展,它實際上只在犀牛工作良好,這是以暴露*可變對象*(一個函數的範圍鏈的頂端對象)的方式,其中變量,參數和函數聲明被綁定。 – CMS 2010-05-31 03:35:34