Skip to content

Instantly share code, notes, and snippets.

@island205
Created January 29, 2012 03:48
Show Gist options
  • Save island205/1697043 to your computer and use it in GitHub Desktop.
Save island205/1697043 to your computer and use it in GitHub Desktop.
var Vector;
Vector = (function() {
/*
构造函数这里使用了默认参数和属性参数
*/ function Vector(x, y) {
var vector;
this.x = x != null ? x : 0;
this.y = y != null ? y : 0;
if (typeof this.x === "object") {
/*
这里的vector为了解决给@x赋值的问题,当然使用
@y=@x.y
@x=@x.x
同样可以,不过代码清晰或者更好点
*/
vector = this.x;
this.x = vector.x;
this.y = vector.y;
}
}
return Vector;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment