I was trying out Joose with node.js and managed to produce code like this:
require('joose'); // WHAT?
Class("Dog", {
methods: {
bark: function() { console.log('woof'); }
}
});
var dog = new Dog();
dog.bark();
I have thought that every require in node.js must be assigned to a variable, contrary to PHP in which you just require the file and it works as if you’d copy its contents to that place.
In this situation Class seems to infiltrate the main scope by itself since if I remove the require statement I get a ReferenceError: Class is not defined.
How does this work?
Joose injects the global variable
Class(global.Class = …), that’s why it’s visible without assigning it into your code specifically.