Skip to content

Instantly share code, notes, and snippets.

@island205
Created January 29, 2012 03:44
Show Gist options
  • Save island205/1697032 to your computer and use it in GitHub Desktop.
Save island205/1697032 to your computer and use it in GitHub Desktop.
class Vector
###
构造函数这里使用了默认参数和属性参数
###
constructor:(@x=0,@y=0) ->
if typeof @x is "object"
###
这里的vector为了解决给@x赋值的问题,当然使用
@y=@x.y
@x=@x.x
同样可以,不过代码清晰或者更好点
###
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