28 lines
536 B
JavaScript
28 lines
536 B
JavaScript
var nextId = 0;
|
|
|
|
export default function local() {
|
|
return new Local;
|
|
}
|
|
|
|
function Local() {
|
|
this._ = "@" + (++nextId).toString(36);
|
|
}
|
|
|
|
Local.prototype = local.prototype = {
|
|
constructor: Local,
|
|
get: function(node) {
|
|
var id = this._;
|
|
while (!(id in node)) if (!(node = node.parentNode)) return;
|
|
return node[id];
|
|
},
|
|
set: function(node, value) {
|
|
return node[this._] = value;
|
|
},
|
|
remove: function(node) {
|
|
return this._ in node && delete node[this._];
|
|
},
|
|
toString: function() {
|
|
return this._;
|
|
}
|
|
};
|