Created
April 1, 2015 13:23
-
-
Save andineck/d500fe17d3b4b6df5b3d to your computer and use it in GitHub Desktop.
javascript adding properties to function, string and array
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 echo(input) { console.log(input);} | |
undefined | |
echo('hallo') | |
VM304:2 hallo | |
undefined | |
// you can add an attribute to a function | |
echo.prop = 'echooo' | |
"echooo" | |
echo.prop | |
"echooo" | |
// you can't add an attribute to a literal string | |
var a = 'asdf' | |
undefined | |
a.prop = 'qwer' | |
"qwer" | |
a.prop | |
undefined | |
// but you can add an attribute to a new String() object | |
var a = new String('asdf') | |
undefined | |
a.prop = 'qwer' | |
"qwer" | |
a.prop | |
"qwer" | |
// and you can as well add an attribute to an array | |
var a = [1,2,3] | |
undefined | |
a.prop = 'qwer' | |
"qwer" | |
a.prop | |
"qwer" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment