Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. Object.create = function (proto) {
  2. function F () {}
  3. F.prototype = proto
  4. return new F()
  5. }
  6.  
  7. function mockNew (constructor, ...args) {
  8. const isPrimitive = result => {
  9. if (result instanceof Object === true) {
  10. return true
  11. }
  12. return false
  13. }
  14.  
  15. const o = Object.create(constructor.prototype)
  16. const result = constructor.apply(o, args)
  17.  
  18. return isPrimitive(result) ? o : result
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement