这里是 raphaeljs graffle 中定义的“拖动器”示例。
var dragger = function () {
this.ox = this.type == "rect" ? this.attr("x") : this.attr("cx");
this.oy = this.type == "rect" ? this.attr("y") : this.attr("cy");
this.animate({"fill-opacity": .2}, 500);
},
move = function (dx, dy) {
var att = this.type == "rect" ? {x: this.ox + dx, y: this.oy + dy} : {cx: this.ox + dx, cy: this.oy + dy};
this.attr(att);
for (var i = connections.length; i--;) {
r.connection(connections[i]);
}
r.safari();
},
up = function () {
this.animate({"fill-opacity": 0}, 500);
},
r = Raphael("holder", 640, 480),
connections = [],
shapes = [ r.ellipse(190, 100, 30, 20),
r.rect(290, 80, 60, 40, 10),
r.rect(290, 180, 60, 40, 2),
r.ellipse(450, 100, 20, 20)
];
我说得对吗:
- move、up、r、connections 和 shapes 是独立变量吗? IE。不是拖动器的方法/属性?
- 这只是等效范围内变量的顺序定义?
move、up 等是否被认为是使用 var 关键字声明的?
感谢您的帮助。爱与和平。
最佳答案
这就像一长串 var
语句。
类似,更易读:
var a = 1, b = 2, c = 3;
在这种情况下,我绝对不会使用这种语法,而是会为每个变量使用单独的一行。按原样阅读真的很难。
简而言之:是的,您在这两个方面都是正确的。这和
完全一样var dragger = ...;
var move = ...;
var up = ....;
...
只是读起来很痛苦。隐藏在声明之间的额外逗号将整个内容连接到 var
语句中。
关于javascript - 请解释通常用于定义 Dragging RaphaelJs 的 javascript 逗号语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17496290/