News for hackers. Stuff that matters.
Re:Apple JavaScript Coding Guidelines by solutionyogi on Sunday October 31, 2010 @10:08PM (#1855087)
As v413 wrote, the main difference is how the function is linked to the instance. If you define a member function inside the constructor, that member function is assigned to each and every object separately. The function code is not shared across all instances. This is extremely unintuitive if you are coming from a statically typed OOP language like Java/C#. To get a behavior similar to what Java/C# gives you, you should use prototype.

To demonstrate the concept, I created this code example:

http://jsbin.com/utuso3/edit [Click on 'Preview' button to run the example code]

I hope that made sense.

Re:Apple JavaScript Coding Guidelines by flatline on Sunday October 31, 2010 @11:24PM (#1855240)
Thanks (and to v413), this does make sense. I hadn't thought it through that each call to the constructor will create a new function object, which was pretty apparent once stated and I re-examined the code.