This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
runFunction : function (name) { | |
this[name](); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Enum() { | |
var that = this; | |
for (var i in arguments) { | |
that[arguments[i]] = i; | |
} | |
this.name = function(value) { | |
for (var key in that) { | |
if (that[key] == value) { | |
return key; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Format emulate | |
String.prototype.format = function () { | |
var args = arguments; | |
return this.replace(/\{\{|\}\}|\{(\d+)\}/g, function (m, n) { | |
if (m == "{{") { return "{"; } | |
if (m == "}}") { return "}"; } | |
return args[n]; | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// apply string format to all elements of array and return result | |
Array.prototype.format=function(prefix) | |
{ | |
var result = []; | |
this.forEach(function(entry) { | |
result.push(prefix.format(entry)); | |
}); | |
return result; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// return last element of array | |
Array.prototype.last = Array.prototype.last || function() { | |
var l = this.length; | |
return this[l-1]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var isValidDate = function(d) { | |
if (Object.prototype.toString.call(d) !== "[object Date]") return false; | |
return !isNaN(d.getTime()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//delete all pattern occurrences | |
String.prototype.deleteOccurrences = function (pattern) { | |
return this.str.replace (RegExp(pattern,'gi'),""); | |
}; | |
//replace all pattern occurrences | |
String.prototype.replaceOccurrences = function (pattern, replace) { | |
return this.str.replace (RegExp(pattern,'gi'),replace); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Date.prototype.format = function(fstr, utc) { | |
var that = this; | |
utc = utc ? 'getUTC' : 'get'; | |
return fstr.replace (/%[YmdHMS]/g, function (m) { | |
switch (m) { | |
case '%Y': return that[utc + 'FullYear'] (); | |
case '%m': m = 1 + that[utc + 'Month'] (); break; | |
case '%d': m = that[utc + 'Date'] (); break; | |
case '%H': m = that[utc + 'Hours'] (); break; | |
case '%M': m = that[utc + 'Minutes'] (); break; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var foo = { | |
hasOwnProperty: function() { | |
return false; | |
}, | |
bar: 'Here be dragons' | |
}; | |
foo.hasOwnProperty('bar'); // siempre devolverá false | |
// Utilice otro objeto con hasOwnProperty y llamelo con 'this' para asignarlo a foo | |
({}).hasOwnProperty.call(foo, 'bar'); // true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var original=28.453 | |
//round "original" to two decimals | |
var result=Math.round(original*100)/100 //returns 28.45 | |
// round "original" to 1 decimal | |
var result=Math.round(original*10)/10 //returns 28.5 | |
//round 8.111111 to 3 decimals | |
var result=Math.round(8.111111*1000)/1000 //returns 8.111 |
OlderNewer