Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //which of obj1 and obj2 will have a func2 method?
- //Explain why obj2.prototype is undefined.
- function func1(){
- this.func2 = function(){
- return this;
- }
- }
- var obj1 = func1();
- var obj2 = new func1();
- console.log(obj1); // undefined
- console.log(obj2); // {func2 : [Function]}
- console.log(obj2.prototype); // undefined
- /*obj2 will have a func2 method because word new calls a function func1 as a constructor*/
- /*all functions have a prototype by default, but func1 becomes a constructor since
- it is invoked using word new, therefor obj2 cannot have a prototype. Also prototype property
- of an object is not directly accessible and should be set with Object.setPrototypeOf method*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement