javascript - 请解释通常用于定义 Dragging RaphaelJs 的 javascript 逗号语法

标签 javascript syntax raphael

这里是 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)
        ];

我说得对吗:

  1. move、up、r、connections 和 shapes 是独立变量吗? IE。不是拖动器的方法/属性?
  2. 这只是等效范围内变量的顺序定义?

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/

相关文章:

raphael - 获取 Raphael 元素的完整当前转换状态(作为对象或字符串)

javascript - 从 vue.js 中的子发射传递时值未定义

java - 如何克服这种 java 语法,使 double 成为字符串?

javascript - 将数组传递给 JavaScript 回调

list - Haskell 有列表切片(即 Python)吗?

javascript - 为每个路径都在 raphael.js 集合中的不同路径应用不同的颜色

javascript - 使用 JavaScript 或 Coldfusion 根据 4 或 5 个坐标点绘制和填充区域

javascript - 如何调用基础 Orbit Slider 的 onChange 函数?

javascript - 单击按钮发送 Ajax 调用并从 aspx.cs(代码隐藏)获取值到 aspx 页面并将其显示在同一页面的输入字段中

javascript - PHP 通过 url 传递字符串编码数据