javascript - node.js res.json messed up -
First I request an '/ init' and the response is Because you defined var resp.success = {"x": 50} In a scope outside @init and @user methods, when you modify / read resp.success in those ways, they are reaching a shared object instance of resp.success. You can set it independently within the @init method and define resp.success: If you use the Underscore JS Library, you can do anything like this: {"x": 50} , Then I request a '/ user' and the response is
{"x": 50, "data": "jack"} . There is no problem till now, but if I make an init again, then it reacts to a
{"x": 50, "data": "jack"} possible?
var resp.success = {"x": 50} exports.init = function (rick, ridge) {res.json (resp.success)}; Export.user = function (req, res) {user.findOne ({_ id: "1234"}) exec (function (err, user) {var response = resp.success; response.data = user.name; res Jason (reaction);}); };
exports.init = function (req, res) {var resp.success = {" X ": 50} res.json (resp.success)}; Export.user = function (req, res) {var resp.success = {"x": 50} User.findOne ({_ id: "1234"}) exec (function (error, user) {var response = resp. Success; response.data = user.name; res.json (feedback);}); };
var resp.success = {"x": 50} Export Init = function (req, res) {var successResponseForThisRequest = _.clone (res.success); Res.json (resp.success)}; Export.user = function (req, res) {user.findOne ({_ id: "1234"}) exec (function (err, user) {var successResponseForThisRequest = _.clone (res.success); response.data = user .name; res.json (feedback);}); };
Comments
Post a Comment