4 ms·
Yes, the Crockford argument. Just because he said it doesn't make it true, though. I don't forget it, because calling a function and creating a new object are
by k3n 13y ago
Yes, the Crockford argument. Just because he said it doesn't make it true, though.
I don't forget it, because calling a function and creating a new object are 2 totally different things. If one can't distinguish between those, then they should probably be tutored in programming 101 because you're going to end up with a lot more serious problems than a ctor accidentally called as a normal function.
Also, and I'm going out on a limb here, but I'd hazard a guess that a majority of programmers using JS will have experience with at least 1 other language (if not many) which use the very same paradigm of creating objects. I can think of a handful off the top of my head, with several of them having a virtually identical syntax (C#, Java, PHP).
- jiggy2011 13y agoNone of those languages AFAIK (I don't really know C#) will allow you to call a constructor function as anything except a constructor function and constructor functions are always constructors and therefor will always return a new object. Javascript in it's infinite wisdom will allow one to use any function as a constructor or not. So code the should be obviously wrong will not generate an error or even a warning, this is not something you want from a language. Since we can't change JS , there is merit to the argument that you should change your own code to avoid even possibly having this problem. Arguments made on the basis of "this is a mistake I am unlikely to make" fill me with skepticism.
- k3n 13y agoYou can shoot yourself in the foot in any language....have you ever tried Perl? Also, if you name your objects and functions like most anyone in CS would suggest, e.g. objects are nouns and functions are verbs, there really shouldn't be a disconnect between the 2 when you need to call them. I am confident that is not a mistake I'll tend to make.
- jiggy2011 13y agoI would suggest movement in the direction of less foot shooting.