Skip to content

Instantly share code, notes, and snippets.

@j2labs
Created September 28, 2011 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save j2labs/1247091 to your computer and use it in GitHub Desktop.
Save j2labs/1247091 to your computer and use it in GitHub Desktop.
> function foo(x,y) {
... args = Array.prototype.join.call(arguments, ",");
... console.log('X:' + x + ' Y:' + y + ' Args:' + args)
... }
> foo(1,2)
X:1 Y:2 Args:1,2
> foo(1,2,3,4,5)
X:1 Y:2 Args:1,2,3,4,5
@gtzilla
Copy link

gtzilla commented Sep 28, 2011

im at a loss, why is this a problem?

perhaps you want this? https://gist.github.com/1247115

@j2labs
Copy link
Author

j2labs commented Sep 28, 2011

If JS doesn't tell you when you've called a function correctly, you are necessarily less sure your code is correct. I forked your gist to add my first attempt at a JS decorator to help make sure arity is correct.

I'm not sure if JS decorators are common but I liked how easy it was to express.

https://gist.github.com/1247166

@gtzilla
Copy link

gtzilla commented Sep 28, 2011

I see what you're saying, but JS doesnt have strong typing either. if the intent is to ensure variables are being correctly passed, it seems like type safety would be something you want. and if that is the case, I would suggest JS is not an appropriate fit. however, i find this flexibility useful. if I want to create new MyObj or whatever, I can, but I'd dont work under the false ideal that I can check types... I also like the fact that prototypes can be grafted / called from any method and used in lots of ways.

js isnt a classic language, seems like traditional software patterns can be informative to JS, but prototypical langs are not classical...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment