Reputation: 35274
I was playing around with closure compiler and put in this code:
var obj = (function() {
function H(a) {
this.a = a
}
var h = new H(1);
h.b=1
return h
})();
I wanted to see if it would convert it to this:
var obj = (function() {
function H(a) {
this.a = a;
this.b = 1
}
var h = new H(1);
return h;
})();
But instead I got this error
JSC_NOT_A_CONSTRUCTOR: cannot instantiate non-constructor at line 6 character 8
var h = new H(1);
What am I doing wrong?
Upvotes: 2
Views: 939
Reputation: 1074285
You have to tell CC that the function is a constructor via @constructor
:
/**
* Makes an H.
* @constructor
*/
function H() {
...
}
Upvotes: 5