Created
January 15, 2014 23:50
-
-
Save bbraithwaite/8447129 to your computer and use it in GitHub Desktop.
Some test object extensions for a blog post.
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
exports.utils = function () { | |
if ( typeof String.prototype.startsWith != 'function' ) { | |
String.prototype.startsWith = function( str ) { | |
return this.substring( 0, str.length ) === str; | |
} | |
}; | |
if ( typeof Object.prototype.sum != 'function' ) { | |
Object.prototype.sum = function( ) { | |
var sum = 0, | |
that = this; | |
for (var i = 0; i < that.length; i++) { | |
sum += that[i]; | |
} | |
return sum; | |
} | |
}; | |
if ( typeof Object.prototype.any != 'function' ) { | |
Object.prototype.any = function( ) { | |
return this.length > 0; | |
} | |
}; | |
if ( typeof Object.prototype.replaceAll != 'function' ) { | |
Object.prototype.replaceAll = function(a, b) { | |
var that = this; | |
while (that.indexOf(a) !== -1) { | |
that = that.replace(a, b); | |
} | |
return that; | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment