访问其他范围的功能,同时可以访问兄弟

时间:2014-10-29 19:45:47

标签: javascript ember.js

我正在尝试更改外部库(ember-data)。但我无法访问我想要改变的功能范围。

我用一个解释和一个非常简化的用例来制作一个js小提琴: 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"));

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

如何访问此范围,更改abcd功能?

1 个答案:

答案 0 :(得分:1)

abcd功能私有您无法更改它,您可以更改say功能,但是您无法访问尚未公开的内容< / p>