//my-class.js
if (typeof module !== "undefined") module.exports = MyClass
function MyClass () {}
MyClass.prototype.doSomething = function () { console.log("hi") }
// other-file.js
var MyClass = require("./my-class")
var mc = new MyClass()
mc.doSomething()
--i
> --
> You received this message because you are subscribed to the Google Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com.
> To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
>
>
Take a look at the post I just made about Example API working in node and browser. I have a stupid simple require module for the browser that I use. It also keeps the global namespace clean.
AJ
Sent from my Google Android
file1:
var my_object = function(){
return { first_func: function() {} };
}();
if(typeof exports !== undefined) exports.my_object = my_object;
file2:
if(typeof exports !== undefined) var my_object = require("file1").my_object;
my_object.new_func = function(){
};
However, that won't necessarily change the original my_object, like it
would in the browser.
Hopefully this helps,
Yours,
Micheil Smith
--
BrandedCode.com
> To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.