sudoclass
Version:
Base, Observable and Delegate classes from the sudo.js library
23 lines (22 loc) • 914 B
JavaScript
// Detect is an argument is a function
// param {*} arg Something to test
// returns {Bool} true of the arg is a function
Function.isFunction = function(arg) {
return typeof arg === 'function';
};
// Method to match Array.isArray syntax for the old favorite
// toString method of detecting a javascript object
// param {*} arg Something to test
// returns {Bool} true if the arg is an actual object
Object.isObject = function(arg) {
return this.prototype.toString.call(arg) === '[object Object]';
};
// String method that replaces delimiters with passed in object values.
// As this method is on the String prototype `.expand({...})` can be called
// on any string
// param {Object} data An object containing the data to insert into the string
// returns {String} the modified string
String.prototype.expand = function(data) {
return this.replace(/\$\{(.+?)\}/g,
function(match, key) {return data[key];});
};