Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
> 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

This comment has been minimized.

Copy link

commented Sep 28, 2011

im at a loss, why is this a problem?

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

@j2labs

This comment has been minimized.

Copy link
Owner Author

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

This comment has been minimized.

Copy link

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
You can’t perform that action at this time.