StructureJS
0.15.2A class based utility library for building modular and scalable web platform applications. Features opt-in classes and utilities which provide a solid foundation and toolset to build your next project.
A Utility class that has several static methods to assist in development.
applyMixins
derivedCtor
baseCtors
TODO: YUIDoc_comment
derivedCtor
Any
baseCtors
Any
class Flies {
fly() {
alert('Is it a bird? Is it a plane?');
}
}
class Climbs {
climb() {
alert('My spider-sense is tingling.');
}
}
class HorseflyWoman implements Climbs, Flies {
climb: () => void;
fly: () => void;
}
Util.applyMixins(HorseflyWoman, [Climbs, Flies]);
clone
obj
Makes a clone of an object.
obj
Object
The object you to clone.
Returns a clone object of the one passed in.
let cloneOfObject = Util.clone(obj);
debounce
callback
wait
immediate
callbackScope
Creates and returns a new debounced version of the passed function which will postpone its execution until after wait milliseconds have elapsed since the last time it was invoked.
callback
Function
The function that should be executed.
wait
Number
Milliseconds to elapsed before invoking the callback.
immediate
Boolean
Pass true for the immediate parameter to cause debounce to trigger the function on the leading instead of the trailing edge of the wait interval. Useful in circumstances like preventing accidental double-clicks on a "submit" button from firing a second time.
callbackScope
Any
The scope of the callback function that should be executed.
Util.debounce(this._onBreakpointChange, 250, false, this);
deletePropertyFromObject
object
value
Removes a list of properties from an object.
Returns the object passed in without the removed the properties.
let obj = { name: 'Robert', gender: 'male', phone: '555-555-5555' }
Util.deletePropertyFromObject(obj, ['phone', 'gender']);
// { name: 'Robert' }
getName
classObject
Returns the name of the function/object passed in.
classObject
Any
Returns the name of the function or object.
let someClass = new SomeClass();
Util.getName(someClass); // 'SomeClass'
Util.getName(function Test(){}); // 'Test'
Util.getName(function (){}); // 'anonymous'
renamePropertyOnObject
object
oldName
newName
Renames a property name on an object.
Returns the object passed in renamed properties.
let obj = { name: 'Robert', gender: 'male', phone: '555-555-5555' }
Util.renamePropertyOnObject(obj, 'gender', 'sex');
// { name: 'Robert', sex: 'male', phone: '555-555-5555' }
toBoolean
strNum
unique
list
Returns a new array with duplicates removed.
list
Array.The array you want to use to generate the unique array.
Returns a new array list of unique items.
uniqueId
[prefix]
Generates a unique ID. If a prefix is passed in, the value will be appended to it.
[prefix]
String
optional
The string value used for the prefix.
Returns the unique identifier.
let property = Util.uniqueId();
// 1
let property = Util.uniqueId('prefixName_');
// prefixName_1