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 it is a special case of
- constructing a new object via the new operator, th Javascript interpreter
- creates a new, empty object, sets some internal properties, and then calls
- constructor function on the new object. Thus, when a function is called
- in a constructor context, the value of this is the new object that the
- interpreter created*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement