我认为这应该做你想要的。如果您觉得它有用,您可能希望将其打包并发布到 Atmosphere。
_.extend(Session, {
/**
* Returns a wrapper around Session
* which automatically prepends
* the specified name to all keys.
*
* @method namespace
* @param {String} name Name of namespace
* @param {String} [separator] Separator for prepended
* name. Default is '-'
* @return {Object} Namespaced session object
*/
namespace: function (name, separator) {
var ns;
separator = separator || '-';
ns = name + separator;
return {
get: function (key) {
return Session.get(ns + key);
},
set: function (key, value) {
return Session.set(ns + key, value);
},
setDefault: function (key, value) {
return Session.setDefault(ns + key, value);
},
equals: function (key, value) {
return Session.equals(ns + key, value);
}
}
}
});