Question

I'm looking to prototype a method into a sub-object. Here is what I mean:

function object() {
    function subObject() {

    }
}

object.subObject.prototype.testMethod = function() {
    alert("test");
};

However, this seems to not work. Any idea on how to go about completing such a task?

Was it helpful?

Solution

You need to create a property of the original function:

MyObject.SubObject = function(...) { ... };

Note that the two "classes" will not be related in any way; instances of either class will have no link to instances of the other class.
This is only useful for namespacing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top