Documentation generator: JsDoc Toolkit 2.4.0
Template: Codeview 1.2
Generated on: 2016-0-4 21:22

Class enchant.Class

A Class representing a class which supports inheritance.

Class Summary
Constructor Attributes Constructor Name and Description
 
enchant.Class(superclass, definition)

Method Summary

Method Attributes Method Name and Description
<static>  
enchant.Class.applyMixingRecipe(target, source)
Applies the defined MixingRecipe to the target class creating a new class definition which is then returned.
<static>  
enchant.Class.create(superclass, definition)
Creates a class.
<static>  
enchant.Class.getInheritanceTree(Constructor)
Get the inheritance tree of this class.
<static>  
enchant.Class.mixClasses(firstClass, secondClass, boolean, Function)
Creates an MixingRecipe out of the second class, applies it to the first class and returns the result.
<static>  
enchant.Class.mixClassesFromRecipe(firstClass, secondClass, recipe, Function)
Uses the given MixingRecipe, applies it to the first class and returns the result - the MixingRecipe should correspond to the secondClass.

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> {Function} enchant.Class.applyMixingRecipe(target, source)
    Applies the defined MixingRecipe to the target class creating a new class definition which is then returned. The target class is not modified directly.
    See also: enchant.Class.MixingRecipe.
    Defined in: mixing.enchant.js.
         var recipe = new enchant.Class.MixingRecipe({
            // ... see enchant.Class.MixingRecipe
         },{
             // ... see enchant.Class.MixingRecipe
         },{
             // ... see enchant.Class.MixingRecipe
         });
         var NewClass = applyMixingRecipe(Class1,recipe);
    Parameters:
    {Function<constructor function created with enchant.Class>} target
    The class to which the recipe will be applied.
    {enchant.Class.MixingRecipe} source
    The MixingRecipe which is used to add new functionality to the target.
    Returns:
    {Function<constructor function created with enchant.Class>} The class which is the result of mixing the target class with the source recipe.
  • <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
  • <static> {Function} enchant.Class.mixClasses(firstClass, secondClass, boolean, Function)
    Creates an MixingRecipe out of the second class, applies it to the first class and returns the result. The default behavior is to take all functions and properties of the second class, including functions and properties defined in its super classes, whereas functions are set to decorate the mixing target.
    Methods which are decorated will automatically call the soureClass method and the mixing target method (using the _mixing property) - so there is no need to handle this yourself.

    Furthermore, a default initialize method will be added which will call the initialize functions of both classes. The signature for the default initialize method is:
    ([firstClass constructor arg 1],...,[firstClass constructor arg n],[secondClass constructor arg 1],...[secondClass constructor arg n])

    Both classes will not be modified.

    See also: enchant.Class.MixingRecipe
    Defined in: mixing.enchant.js.
         var MapGroup = enchant.Class.mixClasses(Map, Group,true);
         var map = new MapGroup(16, 16);
         var SpriteLabel = enchant.Class.mixClasses(Sprite, Label,true);
         var kumaLabel = new SpriteLabel(32,32,'Kuma');
    Parameters:
    {Function<constructor function created with enchant.Class>} firstClass
    The class to which the recipe will be applied.
    {Function<constructor function created with enchant.Class>} secondClass
    The class from which the recipe will be created
    boolean Optional
    useOnlyOwnPropertiesForSecondClass If set to true, the functions and properties of the super classes will be ignored during the recipe creation of the secondClass.
    Function Optional
    initializeMethod If provided, this function will be used to initialize the resulting class instead of the default initialize method.
    Returns:
    {Function<constructor function created with enchant.Class>} The class which is the result of mixing both classes.
  • <static> {Function} enchant.Class.mixClassesFromRecipe(firstClass, secondClass, recipe, Function)
    Uses the given MixingRecipe, applies it to the first class and returns the result - the MixingRecipe should correspond to the secondClass. A default initialize method will be added which will call the initialize functions of both classes. The signature for the default initialize method is:
    ([firstClass constructor arg 1],...,[firstClass constructor arg n],[secondClass constructor arg1],...[secondClass constructor arg n])

    Both classes will not be modified.

    See also: enchant.Class.MixingRecipe
    Defined in: mixing.enchant.js.
         var MapGroup = enchant.Class.mixClasses(Map, Group,true);
         var map = new MapGroup(16, 16);
         var SpriteLabel = enchant.Class.mixClasses(Sprite, Label,true);
         var kumaLabel = new SpriteLabel(32,32,'Kuma');
    Parameters:
    {Function<constructor function created with enchant.Class>} firstClass
    The class to which the recipe will be applied.
    {Function<constructor function created with enchant.Class>} secondClass
    The class which is related to the MixingRecipe, used for the default initialize function.
    {enchant.Class.MixingRecipe} recipe
    The recipe which is applied to the first class - should correspond to the secondClass.
    Function Optional
    initializeMethod If provided, this function will be used to initialize the resulting class instead of the default initialize method.
    Returns:
    {Function<constructor function created with enchant.Class>} initializeMethod The class which is the result of mixing both classes using the recipe.