diff options
Diffstat (limited to 'deps/npm/node_modules/npmconf/node_modules/config-chain/node_modules/proto-list/proto-list.js')
-rw-r--r-- | deps/npm/node_modules/npmconf/node_modules/config-chain/node_modules/proto-list/proto-list.js | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/deps/npm/node_modules/npmconf/node_modules/config-chain/node_modules/proto-list/proto-list.js b/deps/npm/node_modules/npmconf/node_modules/config-chain/node_modules/proto-list/proto-list.js index 67d250387c..b55c25c052 100644 --- a/deps/npm/node_modules/npmconf/node_modules/config-chain/node_modules/proto-list/proto-list.js +++ b/deps/npm/node_modules/npmconf/node_modules/config-chain/node_modules/proto-list/proto-list.js @@ -1,6 +1,13 @@ module.exports = ProtoList +function setProto(obj, proto) { + if (typeof Object.setPrototypeOf === "function") + return Object.setPrototypeOf(obj, proto) + else + obj.__proto__ = proto +} + function ProtoList () { this.list = [] var root = null @@ -9,7 +16,7 @@ function ProtoList () { set: function (r) { root = r if (this.list.length) { - this.list[this.list.length - 1].__proto__ = r + setProto(this.list[this.list.length - 1], r) } }, enumerable: true, @@ -35,24 +42,24 @@ ProtoList.prototype = , push : function (obj) { if (typeof obj !== "object") obj = {valueOf:obj} if (this.list.length >= 1) { - this.list[this.list.length - 1].__proto__ = obj + setProto(this.list[this.list.length - 1], obj) } - obj.__proto__ = this.root + setProto(obj, this.root) return this.list.push(obj) } , pop : function () { if (this.list.length >= 2) { - this.list[this.list.length - 2].__proto__ = this.root + setProto(this.list[this.list.length - 2], this.root) } return this.list.pop() } , unshift : function (obj) { - obj.__proto__ = this.list[0] || this.root + setProto(obj, this.list[0] || this.root) return this.list.unshift(obj) } , shift : function () { if (this.list.length === 1) { - this.list[0].__proto__ = this.root + setProto(this.list[0], this.root) } return this.list.shift() } @@ -74,7 +81,7 @@ ProtoList.prototype = // handle injections var ret = this.list.splice.apply(this.list, arguments) for (var i = 0, l = this.list.length; i < l; i++) { - this.list[i].__proto__ = this.list[i + 1] || this.root + setProto(this.list[i], this.list[i + 1] || this.root) } return ret } |