美文网首页
node.js填坑

node.js填坑

作者: 彬彬彬boboc | 来源:发表于2018-04-24 16:07 被阅读0次

关于在node.js 导出模块的问题填坑

构造函数 的导出跟es6的class类导出的顺序问题

module.exports = Score;

function Score(name){

this.name = name;

}

Score.prototype.getName = function() {

console.log(this.name);

};

在构造函数之前module.exports= Score;这样是没问题的但是

后面用es6  class类的导出就不一样了

module.exports= Score;//必须写在定义类的后面

class Score{

constructor(name){

this.name = name;

// this.getName();

}

getName(){

console.log(this.name);

}

}

module.exports = Score;

相关文章

网友评论

      本文标题:node.js填坑

      本文链接:https://www.haomeiwen.com/subject/pxfwhftx.html