Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //which of obj1 and obj2 will have a func2 method?
  2. //Explain why obj2.prototype is undefined.
  3.  
  4. function func1(){
  5.     this.func2 = function(){
  6.         return this;
  7.     }
  8. }
  9.  
  10. var obj1 = func1();
  11. var obj2 = new func1();
  12.  
  13. console.log(obj1);           // undefined
  14. console.log(obj2);           // {func2 : [Function]}
  15. console.log(obj2.prototype); // undefined
  16.  
  17. /*obj2 will have a func2 method because it is a special case of
  18. constructing a new object via the new operator, th Javascript interpreter
  19. creates a new, empty object, sets some internal properties, and then calls
  20. constructor function on the new object. Thus, when a function is called
  21. in a constructor context, the value of this is the new object that the
  22. interpreter created*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement