node.js - How do I keep a session variable from changing? -
so i've got session variable, req.session.user, contains object corresponding user account. when this,
var user = req.session.user; var fakeuser = user; fakeuser.username = 'bob';
user.username , req.session.user.username both changed 'bob' well. how prevent this?
clone
function clone(obj) { if (null == obj || "object" != typeof obj) return obj; var copy = obj.constructor(); (var attr in obj) { if (obj.hasownproperty(attr)) copy[attr] = obj[attr]; } return copy; }
Comments
Post a Comment