Frage

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?

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top