extended prototypes
by peterbenoit
HTML
<script src="http://underscorejs.org/underscore-min.js"></script>
<script src="http://backbonejs.org/backbone-min.js"></script>
<script src="http://requirejs.org/docs/release/2.0.6/minified/require.js"></script>
<script src="http://modernizr.com/downloads/modernizr.js"></script>
<link rel="stylesheet" href="http://necolas.github.com/normalize.css/2.0.1/normalize.css">
JavaScript
String.prototype.isImage = function(str){
return /(jpe?g|png|gif)$/i.test(str);
}
console.log("".isImage("animated.gif"));
Boolean.prototype.XOR=function(bool2){
var bool1=this.valueOf();
return (bool1==true && bool2==false) || (bool2==true && bool1==false);
}
console.log(true.XOR(false)); // true
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, "");
}
String.prototype.lTrim = function () {
return this.replace(/^\s+/g, "");
}
String.prototype.rTrim = function () {
return this.replace(/\s+$/g, "");
}
String.prototype.left = function(len) {
return (len > this.length) ? this : this.substring(0, len);
}
String.prototype.right = function(len) {
return (len > this.length) ? this : this.substring(this.length - len);
}
String.prototype.beginsWith = function(t) {
return (t.toLowerCase() == this.substring(0, t.length).toLowerCase());
}
String.prototype.endsWith = function(t) {
return (t.toLowerCase() == this.substring(this.length - t.length).toLowerCase());
}