Guest User

Untitled

a guest
Jun 20th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. ## Doesn't work
  2.  
  3. ```js
  4. var fn = (function(){
  5. return function(){}
  6. })();
  7.  
  8. Object.defineProperty(fn, "name", {
  9. value: "Others",
  10. configurable: true
  11. });
  12.  
  13. var obj1 = new fn();
  14. var obj2 = Object.create(fn.prototype);
  15. var obj3 = Object.create({constructor: fn})
  16. ```
  17.  
  18. ```js
  19. Object.create({constructor: {name: "foo"}})
  20. ```
  21.  
  22. ```js
  23. var fn = new Function();
  24.  
  25. Object.defineProperty(fn, "name", {
  26. value: "Others",
  27. configurable: true
  28. });
  29.  
  30. var obj1 = new fn();
  31. ```
  32.  
  33. ```js
  34. var thing3 = (function(){
  35. function NamedThing2(){}
  36. NamedThing2.toString = function(){ return "function NamedThing333(){}" }
  37. console.log( NamedThing2.toString() )
  38. return Object.create(NamedThing2.prototype)
  39.  
  40. })()
  41. ```
  42.  
  43. ## Works, but doesn't allow me to arbitrarily set constructor name
  44.  
  45. ```js
  46. var NamedThing = function(){}
  47. var thing = Object.create(NamedThing.prototype)
  48. ```
  49.  
  50. ```js
  51. var obj = Object.create({constructor: function bar(){}})
  52. ```
Add Comment
Please, Sign In to add comment