Methods
-
<static> extend( [ definition ] ) → {function}
Creates a new class that inherits from this one which in turn allows itself to be extended.
-
Description
Parameters
Name Type Attributes Description definition
Object <optional> An object containing any methods to implement/override.
Returns
Examples
// create a base Person class var Person = FooGallery.utils.Class.extend({ construct: function(isDancing){ this.dancing = isDancing; }, dance: function(){ return this.dancing; } }); var Ninja = Person.extend({ construct: function(){ // Call the inherited version of construct() this._super( false ); }, dance: function(){ // Call the inherited version of dance() return this._super(); }, swingSword: function(){ return true; } }); var p = new Person(true); console.log( p.dance() ); // => true var n = new Ninja(); console.log( n.dance() ); // => false console.log( n.swingSword() ); // => true console.log( p instanceof Person && p.constructor === Person && p instanceof FooGallery.utils.Class && n instanceof Ninja && n.constructor === Ninja && n instanceof Person && n instanceof FooGallery.utils.Class ); // => true
Details
-
<static> override( name, fn )
Overrides a single method on this class.
-
Description
This is a helper method for overriding a single function of a FooGallery.utils.Class or one of its child classes. This uses the FooGallery.utils.fn.addOrOverride method internally and simply provides the correct prototype.
Parameters
Name Type Description name
string The name of the function to override.
fn
function The new function to override with, the
_super
method will be made available within this function.Examples
var Person = FooGallery.utils.Class.extend({ construct: function(isDancing){ this.dancing = isDancing; }, dance: function(){ return this.dancing; } }); var p = new Person(true); console.log( p.dance() ); // => true Person.override("dance", function(){ // Call the original version of dance() return !this._super(); }); console.log( p.dance() ); // => false
Details