Guest User

Untitled

a guest
Feb 21st, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. // examinining the basics of an object
  2.  
  3. function Ninja(){}
  4. var ninja = new Ninja();
  5.  
  6. console.log( typeof ninja == "object" ? true : false) // true. the type of the instance is still an object.
  7. console.log( ninja instanceof Ninja) // true, The object was instantiated properly.
  8. console.log( ninja.constructor == Ninja); // true, The ninja object was created by the Ninja function.
  9.  
  10. // We can still use the constructor to build other instances.
  11. var ninjaB = new ninja.constructor();
  12. console.log( ninjaB instanceof Ninja); // true, Still a ninja object.
  13.  
  14. var ninja3 = (function(){
  15. function Ninja(){}
  16. return new Ninja();
  17. })();
  18.  
  19. var ninja4 = new ninja3.constructor;
  20. console.log( ninja3.constructor == ninja4.constructor); // true, the ninjas come from the same source.
Add Comment
Please, Sign In to add comment