似乎我不理解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,或者我应该修补拉斐尔来做这样的事情?
http://jsfiddle.net/YV2SR/4/
more simple jsfiddle - without raphael at all
发布于 2012-08-08 01:02:11
啊,最后一次编辑。
不,你不能在一个对象构造函数中定义var $,而不修改源代码以某种方式公开$。这是相当于私有属性的JavaScript。
https://stackoverflow.com/questions/11848394
复制相似问题