Skip to content

Instantly share code, notes, and snippets.

@jackey
Created February 23, 2012 07:46
Show Gist options
  • Save jackey/1891370 to your computer and use it in GitHub Desktop.
Save jackey/1891370 to your computer and use it in GitHub Desktop.
create instance as soon as required module
//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 ??
@xianlihua
Copy link

class 应该是关键词吧

@jackey
Copy link
Author

jackey commented Feb 23, 2012

不是这个原因.javascript 没有clas关键词;

如果我这么用 就没有错:

var class = require('./class');
var c = new class
c.add();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment