Skip to content

Commit

Permalink
converted to setPrototypeOf for forward and backward compat
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleytodd committed Feb 23, 2016
1 parent 405a758 commit 79f556e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 16 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* MIT Licensed
*/

var setPrototypeOf = Object.setPrototypeOf || ({__proto__:[]} instanceof Array ? setProtoOf : mixinProperties)

/**
* Expose `Proto`.
Expand Down Expand Up @@ -41,7 +42,7 @@ function Proto(protos, options) {
var middleware = function setProto() {
var i = arguments.length
while (i--) {
arguments[i].__proto__ = middleware[_protos[i]].proto
setPrototypeOf(arguments[i], middleware[_protos[i]].proto)
}
}

Expand All @@ -50,9 +51,10 @@ function Proto(protos, options) {
while (i--) {
var name = _protos[i]
var prop = middleware[name] = {
proto: { __proto__: protos[name].prototype }
proto: {}
, _opts: opts
}
setPrototypeOf(prop.proto, protos[name].prototype)
prop.defineProperty = defineProperty.bind(prop)
prop.defineProperties = defineProperties.bind(prop)
}
Expand All @@ -62,7 +64,7 @@ function Proto(protos, options) {


/**
* define a property onto the __proto__
* define a property onto the prototype
*/
function defineProperty(name, descriptor) {
if (!name) {
Expand Down Expand Up @@ -90,7 +92,7 @@ function defineProperty(name, descriptor) {


/**
* define properties on __proto__ via an object map
* define properties on prototype via an object map
*/
function defineProperties(props) {
if (!props) {
Expand All @@ -109,3 +111,13 @@ function defineProperties(props) {

Object.defineProperties(this.proto, props)
}

function setProtoOf(obj, proto) {
obj.__proto__ = proto
}

function mixinProperties(obj, proto) {
for (var prop in proto) {
obj[prop] = proto[prop]
}
}
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
"extend",
"inject"
],
"dependencies": {
},
"devDependencies": {
"mocha": "^2.0.1",
"istanbul": "0.3.2"
Expand Down

0 comments on commit 79f556e

Please sign in to comment.