![]() ![]() ![]() The prototype property is available if people want to inherit. When they want one, they call Xyz.create(), and get back a new, initialized object of my type. the create() function is for users of my type. I return an object with a create() function, and a prototype property. This means I have a private space to work without making a mess in the global namespace. You can find his object creation function here: if (typeof Object.create != 'function') )(). However, JS is as it is so go and use "new". He (IMHO rightly) says that the way it turned out JS is conflicted, prototype based but with this one thing from "classical class" inheritance languages. Most programming languages contain good and bad parts, but JavaScript has more than its share of the bad, having been developed and released in a hurry before it could be refined. I understand this particular statement to be more on an "academic" level, what SHOULD have been HAD the language been designed "right" and not with some leftovers of the class-based inheritance stuff. However, the YUI(3) team itself uses "new", and they DO follow his recommendations (since he's the Yahoo chief JS architect (UPDATE: he moved on, but the statement was true when this response was originally written). ![]() Crockford gives an example for an object creation function as should have been provided by JS itself in one of his Javascript talks available on ![]()
0 Comments
Leave a Reply. |