-
-
Save thapakazi/7213295 to your computer and use it in GitHub Desktop.
Splat Array Example
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
#try this in scratchpad | |
function func (obj /*, *args*/) { | |
var star_args = Array.prototype.slice.call (arguments, func.length); | |
/* now star_args[0] is the first undeclared argument */ | |
for (i=0;i<star_args.length;i++){ | |
alert(star_args[i]); | |
} | |
alert(y); | |
} | |
func(1,10,"hello world",2,5,6.22); | |
#it works |
function func (obj /, *args/) {
pobj= JSON.parse(obj)
var star_args = Array.prototype.slice.call (arguments, func.length);
alert(pobj.name);
//outputs name Tintin
for (i=0;i<star_args.length;i++){
alert(pobj.star_args[i]);
}
}
var json = '{"name":"Tintin","addr":"Kausaltar"}'
//function call with a json object
func(json,'name','addr');
/*
Exception: pobj.star_args is undefined
func@Scratchpad/1:10
@Scratchpad/1:18
*/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
coffe version here
func = (obj) -> #, *args
star_args = Array::slice.call(arguments_, func.length)
now star_args[0] is the first undeclared argument
i = 0
while i < star_args.length
alert star_args[i]
i++
jsonObj = "apple"
func jsonObj, "params1", "params2", "params3"