我有以下的CoffeeScript代码:的CoffeeScript - 传递参数传递给超构造问题
planet = new Planet p5, {x: 100, y: 100, diameter: 20}
和别的地方:
class GameObject
constructor: (@p5, @x, @y) ->
@selected = false
class Planet extends GameObject
constructor: (p5, opts) ->
super (p5 opts.x opts.y)
@diameter = opts.diameter
,为super
线,它说:
Uncaught TypeError: Property 'x' of object #< Object> is not a function
,它只是:
class Planet
constructor: (p5, opts) ->
@x = opts.x
@y = opts.y
@diameter = opts.diameter
@selected = false
即使它成为一个更通用的GameObject
的孩子......我尝试了一些重新安排,使其工作,但所有入侵。不确定它是否与CoffeeScript或JavaScript相关。官方网站上的“尝试CoffeScript”的东西在这里没有错误。浏览器是铬...这里有什么问题,我如何克服这一点?