Created
September 28, 2011 05:54
-
-
Save j2labs/1247091 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
> 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 |
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
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