Created
February 23, 2012 07:46
-
-
Save jackey/1891370 to your computer and use it in GitHub Desktop.
create instance as soon as required module
This file contains 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
//File class.js | |
class = module.exports = function () { | |
} | |
class.prototype.add = function () {console.log('hello')}; | |
//File index.js | |
var class = new require('./class')(); | |
class.add(); | |
// Error: | |
//TypeError: Cannot call method 'add' of undefined | |
// Why have error ?? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
不是这个原因.javascript 没有clas关键词;
如果我这么用 就没有错:
var class = require('./class');
var c = new class
c.add();