object.js
function Helo(){ var name; this.setName = function(pName){ this.name = pName; } this.sayHelo = function(){ console.log('Helo ' + this.name); } }; //exports.Helo = Helo; module.exports = Helo;
object_use.js
var Helo = require('./object'); helo1 = new Helo(); helo1.setName('koma'); helo1.sayHelo(); helo2 = new Helo(); helo2.setName('xiaoma'); helo2.sayHelo();
実行結果:
$node object_use.js Helo koma Helo xiaoma
0 件のコメント:
コメントを投稿