-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export default function(undefined) { | ||
var Temp = function() {}; | ||
return function (prototype, propertiesObject) { | ||
if(prototype !== Object(prototype)) { | ||
throw TypeError( | ||
'Argument must be an object, or null' | ||
); | ||
} | ||
Temp.prototype = prototype || {}; | ||
var result = new Temp(); | ||
Temp.prototype = null; | ||
if (propertiesObject !== undefined) { | ||
Object.defineProperties(result, propertiesObject); | ||
} | ||
|
||
// to imitate the case of Object.create(null) | ||
if(prototype === null) { | ||
result.__proto__ = null; | ||
} | ||
return result; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import create from './create'; | ||
|
||
if (typeof Object.create !== 'function') { | ||
Object.create = create(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import test from 'ava'; | ||
import create from './create'; | ||
|
||
test('should create object with given prototype', t => { | ||
const foo = { foo: 'foo' }; | ||
|
||
const object = create()(foo); | ||
|
||
t.deepEqual(object.__proto__, { foo: 'foo' }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters