I found that namespace.ex2.method1 is not a function.
Right. In JavaScript, you do not directly assign prototypes to objects (although this becomes possible as a new fifth release , see below). Instead, you set up prototypes of constructor functions, which are then assigned to the objects built by these functions. So if you did
var obj = new namespace.ex2(); obj.method1();
... you would find a method. (Although there is no reason why you cannot call namespace.ex2.prototype.method1(); if you want.)
This indirect approach is somewhat unusual for a prototypical language. The fifth edition of ECMAscript introduces the means of creating an object and directly defining its prototype ( Object.create ), but this is a fairly new addition to the language.
Read more about prototypes, methods, settings of prototype chains, etc. you can find this article from Crockford and this is a less (but perhaps more familiar, and, of course, pragmatic) really interesting reading.
source share