Created
January 29, 2012 03:44
-
-
Save island205/1697032 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Vector | |
### | |
构造函数这里使用了默认参数和属性参数 | |
### | |
constructor:(@x=0,@y=0) -> | |
if typeof @x is "object" | |
### | |
这里的vector为了解决给@x赋值的问题,当然使用 | |
@[email protected] | |
@[email protected] | |
同样可以,不过代码清晰或者更好点 | |
### | |
vector=@x | |
@x=vector.x | |
@y=vector.y | |
### | |
test start | |
### | |
v=new Vector() | |
console.log v.x,v.y | |
v=new Vector(1,1) | |
console.log v.x,v.y | |
v=new Vector {x:1,y:1} | |
console.log v.x,v.y | |
### | |
test end | |
### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment