前面所用到的String、Array、Sprite等都是类,我们已经使用过系统为它们编好的一些方法了。在 puriset 的脚本中除去最后的 Main脚本全部是类定义。
在例如定义 Person 的类时是这样的:
class Person end
class Person end
也就是说,我们可以实例化这个类。
class Person end
class Person end
class Person end
class Person end
这样在实例化对象的时候,会默认先调用initialize方法来为@name赋初值
class Person end
在这个例子中, initialize 方法把参数 name 的取值赋给属性 @name作为初值。
class Person end