Created
July 12, 2013 17:47
-
-
Save oomlaut/5986328 to your computer and use it in GitHub Desktop.
Extend the String superclass to enable a more OO-elegant way of joining strings.
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(){ | |
String.prototype.concat = function(argument){ | |
if ( arguments.length > 0 ){ | |
if ( typeof argument === "string" ) { | |
return this + argument; | |
} else { | |
var str = ""; | |
for ( var i in argument ){ | |
str += argument[i]; | |
} | |
return this + str; | |
} | |
} | |
return this; | |
}; | |
})(); | |
console.log("foo".concat("bar")); | |
console.log("Hello".concat([" World", "!"])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment