javascript - NodeJS Object Require -
scenario: login account, , player object populated data db. object has methods update db.
issue: what's best way define such object? how define node can use these methods @ will? need pass player object parameter or have re-require (will re-define object?) req parameter "expire" or have wrong scope?
module.exports = { createplayer:player } function player(id,con,mysql,req) { this.id = id; this.x; this.y; this.con = con; this.mysql = mysql; this.req = req; } player.prototype = { move:function() { } } and lastly, how require , initialize node?
var player = (new require("player")); //this guess honest
player.js
function player(id,con,mysql,req) { this.id = id; this.x; this.y; this.con = con; this.mysql = mysql; this.req = req; } player.prototype = { move:function() { } } module.exports = player; use in file now
var player = require("./player"); // create player instance var p = new player(id,con,mysql,req);
Comments
Post a Comment