Skip to content

Instantly share code, notes, and snippets.

@andineck

andineck/prop.js

Created Apr 1, 2015
Embed
What would you like to do?
javascript adding properties to function, string and array
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