访问其他作用域中的函数,同时具有对同级函数的访问权限

Access function in other scope, while having acces to a sibling

本文关键字:函数 访问 访问权 权限 作用域 其他      更新时间:2023-09-26

我正在尝试更改一个外部库(ember数据)。但是我无法访问我想要更改的函数的范围。

我做了一个解释和一个非常简单的用例:http://jsfiddle.net/yr5Lmzyk/3/

// =========== External libary (cannot be changed)---------------------------
var ex = {};
(function (__exp__){
    ob = {
        prefix: 'object-prefix',
        say: function(word){
             return this.prefix + "|" + abcd(word);   
        }
    };
    function abcd(a){
     return a + "|function-postfix";   
    }
__exp__.ob = ob;
}(ex));
var ob = ex.ob;
// ================= Available/ ajustable code ---------------------
// i want to change the working of the abcd function.
// in the real case abcd is used in many functions of ob, but i only want to change that function.
$("#content").html(ob.say("call-parameter"));

上半部分是"外部"库,我无法更改。下面是我的代码,我可以访问它。当我在ob对象上运行say方法时,它使用函数abcd。我想改变这个功能的工作方式。

如何访问此范围,以更改abcd函数?

abcd函数是其private您不能更改它,您可以更改say函数,但您无法访问尚未公开的