Skip to content

Instantly share code, notes, and snippets.

@thapakazi
Last active December 26, 2015 20:59
Show Gist options
  • Save thapakazi/7213295 to your computer and use it in GitHub Desktop.
Save thapakazi/7213295 to your computer and use it in GitHub Desktop.
Splat Array Example
#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
@thapakazi
Copy link
Author

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"

@thapakazi
Copy link
Author

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