Created
July 3, 2010 04:45
-
-
Save infynyxx/462316 to your computer and use it in GitHub Desktop.
Node.js Module Loading Incompatibility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*This will work when loaded as module*/ | |
exports.area = function(radius) { | |
return PI * radius * radius; | |
}; | |
exports.circumference = function(radius) { | |
return PI * 2 * radius; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*This will not work when loaded as module*/ | |
var exports = {}; | |
var PI = 3.14; | |
exports.area = function(radius) { | |
return PI * radius * radius; | |
}; | |
exports.circumference = function(radius) { | |
return PI * 2 * radius; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var circle = require('./module_load_correct'), //module_load_incorrect | |
sys = require('sys'); | |
sys.puts('The area of circle with radius 4 is ' + circle.area(4)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment