I am trying to access the static properties of a class without using an instance of the class to do so. I tried adapting the method in this post, but to no avail. All I get is test.getInstanceId is not a function
Based on how I am creating the class (below), how can I do this? Here is a fiddle.
test = (function() {
var currentInstance;
function test() {
this.id = 0;
currentInstance = this;
// this won 't work
this.getInstanceId = function() {
return currentInstance.id;
}
}
test.prototype.setId = function(id) {
this.id = id;
}
return test;
})();
var myTest = new test();
myTest.setId(1);
console.log(myTest.id)
console.log(test.getInstanceId());