在Raphael.js中扩展_engine

时间:2012-08-07 14:40:31

标签: javascript raphael

似乎我不明白javascript中的一些基本原理,

我有以下代码:

Raphael.fn.group = function() {
    var out = Raphael._engine.group(this);
    this.__set__ && this.__set__.push(out);
    return out;
};
(window.Raphael.svg &&
function(e) {
    e.group = function(svg) {
        //Want this to be called $ function defined in Raphael._engine 
        // as var $=function(..){..}
        // line 3780
        var el = $("g");
        svg.canvas && svg.canvas.appendChild(el);
        var res = new Element(el, svg);
        res.type = "group";
        return res;
    }
})(window.Raphael._engine);
var paper = Raphael("out", 800, 600);
//test with circle;
paper.circle(100, 100, 50);
//test with new method;
paper.group();​

所以我发现$ near评论行来自全球范围,而不是来自Raphael._engine范围,这里有什么方法可以扩展_engine,或者我应该修补raphael来做这些事情?

http://jsfiddle.net/YV2SR/4/

more simple jsfiddle - without raphael at all

1 个答案:

答案 0 :(得分:0)

啊,最后一次编辑。

不,你不能在对象构造函数中定义var $而不改变源代码以暴露$ somehow。这就是私有财产的JavaScript等价物。