I am creating a instance of a class using the following code:
test = new function(){
...
}
However, base has no prototype because it was created from an anonymous function (I'm guessing this is the reason?). This leaves me unable to create any public functions for the instance.
You could argue I could get around this by simply doing:
function testClass(){
...
}
test = new testClass()
and then attaching public functions to testClass. But this forces me to do unnecessary namespacing. In particular, if I were to name my class this.is.a.space, then what would I call my instance? this.is.a.spaceInstance? this.is.a.space.Instance?
Is there a convention for this sort of thing?
You can still code the anonymous function and use
.__proto__
to access its prototype like this:However, you only have one instance so you could also just use:
I'm not completely sure what exactly you're trying to accomplish, but as for the naming, it is usual to name the class like
SomeClass
and other variables (like instances) along the lines ofsomeVariable
. JavaScript is case-sensitive so you could useTestClass
/testClass
.