Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converted to setPrototypeOf #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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