3 ms·
Hate to dry off the blanket but they just forgot the `new` keyword for `this` ;) var $ = new (function() { this.version = '1.2.3'; })(); console.log($
by momokoko 7y ago
Hate to dry off the blanket but they just forgot the `new` keyword for `this` ;)
var $ = new (function() { this.version = '1.2.3'; })();
console.log($.version); // '1.2.3'
EDIT:
Or if you really want to abuse the spec
var $ = (function() { if (!(this instanceof arguments.callee)) return new arguments.callee(); this.version = '1.2.3' })();
console.log($.version); // '1.2.3'
- furgooswft13 7y agolol. But yes, I do really want to abuse the spec. You could also do this: var $ = (function(){ this.version = '1.2.3'; return this; }).call({}) console.log($.version); //1.2.3 But that's not quite as ugly so I guess I lose some points.