Class enchant.Class
A Class representing a class which supports inheritance.
- Defined in: enchant.js
Constructor Attributes | Constructor Name and Description |
---|---|
enchant.Class(superclass, definition)
|
Method Summary
Method Attributes | Method Name and Description |
---|---|
<static> |
enchant.Class.create(superclass, definition)
Creates a class.
|
<static> |
enchant.Class.getInheritanceTree(Constructor)
Get the inheritance tree of this class.
|
Class Detail
enchant.Class(superclass, definition)
- Parameters:
- {Function} superclass Optional
- The class from which the new class will inherit the class definition.
- {*} definition Optional
- Class definition.
Method Detail
-
<static> enchant.Class.create(superclass, definition)Creates a class. When defining a class that extends from another class, the constructor of the other class will be used by default. Even if you override this constructor, you must still call it to ensure that the class is initialized correctly.
// Creates a Ball class. var Ball = Class.create({ // Ball's constructor initialize: function(radius) { // ... code ... }, // Defines a fall method that doesn't take any arguments. fall: function() { // ... code ... } }); // Creates a Ball class that extends from "Sprite" var Ball = Class.create(Sprite); // Creates a Ball class that extends from "Sprite" var Ball = Class.create(Sprite, { // Overwrite Sprite's constructor initialize: function(radius) { // Call Sprite's constructor. Sprite.call(this, radius * 2, radius * 2); this.image = core.assets['ball.gif']; } });
- Parameters:
- {Function} superclass Optional
- The class from which the new class will inherit the class definition.
- {*} definition Optional
- Class definition.
-
<static> {Function[]} enchant.Class.getInheritanceTree(Constructor)Get the inheritance tree of this class.
- Parameters:
- {Function} Constructor
- Returns:
- {Function[]} Parent's constructor