mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2026-04-30 00:00:04 +08:00
Added binding of methods
This commit is contained in:
@@ -14,14 +14,7 @@ class Utilities {
|
||||
/**
|
||||
* Bindings
|
||||
*/
|
||||
this.getButtonClass = this.getButtonClass.bind(this);
|
||||
this.getButtonDisplayName = this.getButtonDisplayName.bind(this);
|
||||
this.getUpdatedInput = this.getUpdatedInput.bind(this);
|
||||
this.updateCaretPos = this.updateCaretPos.bind(this);
|
||||
this.updateCaretPosAction = this.updateCaretPosAction.bind(this);
|
||||
this.isMaxLengthReached = this.isMaxLengthReached.bind(this);
|
||||
this.camelCase = this.camelCase.bind(this);
|
||||
this.countInArray = this.countInArray.bind(this);
|
||||
Utilities.bindMethods(Utilities, this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -372,6 +365,19 @@ class Utilities {
|
||||
return Boolean(this.maxLengthReached);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Bind all methods in a given class
|
||||
*/
|
||||
static bindMethods(myClass, instance) {
|
||||
for (let myMethod of Object.getOwnPropertyNames(myClass.prototype)) {
|
||||
let excludeMethod = (myMethod === "constructor" || myMethod === "bindMethods");
|
||||
if (!excludeMethod) {
|
||||
instance[myMethod] = instance[myMethod].bind(instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms an arbitrary string to camelCase
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user