Function.prototype.setStatic >= 0.1.4
Purpose
Set a static method or property on the given constructor
Syntax
Function#setStatic
(
Stringname
Functionvalue
);
Can also be used to set a static property. This won't fire an error when not given a function, unlike setMethod
Parameters
name
- The name of the property (defaults to name of the function, if a function is set)
value
- The value of the property. Probably a function, but can be anything
Examples
Create a class and add a static method
// Create the new class
var Base = Function.inherits(function Base() {});
// Add the static method
Base.setStatic(function getClassName() {
return this.name;
});
Base.getClassName();>>> "Base"
Static methods are also inherited by descendants
// Create the child class
var Child = Function.inherits('Base', function Child() {});
Child.getClassName();>>> "Child"
Comments