because by default prototype object has 2 fields. one is constructor and second is prototype. but for this line "Lenovo.prototype = Object.create(Mobile.prototype);" we override the prototype object and now it has not second field called constructor. so that's why we need to reset the constructor. and need to put this line as well "Lenovo.prototype.constructor = Lenovo;"
sir here i think is a demerit function extend (child,parent) { child.prototype = Object.create(parent.prototype); child.prototype.constructor = child; } is fine, but when i try to add child.prototype.anything = function () { return(this.xyz);
} and if i try to access this function through the object of its class it shows this function is not defined. why?
because by default prototype object has 2 fields. one is constructor and second is prototype. but for this line "Lenovo.prototype = Object.create(Mobile.prototype);" we override the prototype object and now it has not second field called constructor. so that's why we need to reset the constructor. and need to put this line as well "Lenovo.prototype.constructor = Lenovo;"
Default Behavior Without Reset • When you use Object.create() to set up inheritance: Ex. Child.prototype = Object.create(Parent.prototype); • The prototype of the child is now linked to the parent's prototype. • However, the constructor property of the child prototype now points to the parent's constructor instead of the child class constructor. Reset the Constructor? • Manually reset Child.prototype.constructor to Child to ensure instances of Child correctly identify their constructor. Ex. Child.prototype.constructor = Child; If you don’t reset the constructor, checking instance.constructor could give wrong results. For example, if you want to check if an object is an instance of a certain class, it might mistakenly say it belongs to the parent class.
because by default prototype object has 2 fields. one is constructor and second is prototype. but for this line "Lenovo.prototype = Object.create(Mobile.prototype);" we override the prototype object and now it has not second field called constructor. so that's why we need to reset the constructor. and need to put this line as well "Lenovo.prototype.constructor = Lenovo;"
because by default prototype object has 2 fields. one is constructor and second is prototype. but for this line "Lenovo.prototype = Object.create(Mobile.prototype);" we override the prototype object and now it has not second field called constructor. so that's why we need to reset the constructor. and need to put this line as well "Lenovo.prototype.constructor = Lenovo;"
because by default prototype object has 2 fields. one is constructor and second is prototype. but for this line "Lenovo.prototype = Object.create(Mobile.prototype);" we override the prototype object and now it has not second field called constructor. so that's why we need to reset the constructor. and need to put this line as well "Lenovo.prototype.constructor = Lenovo;"
// class var Mobile=function (){ }; // prtotype method Mobile.prototype.getModel=function(){ return this.model;}
var mob=new Mobile(); document.write(mob.getModel()); sir mujhe yahi par parameter deke model print karana ho to sir hum karenge, sir please help and reply to me
It will help to understand the concept easily. I also follow one pattern to explain various languages and frameworks so if A Person learns Django at Geekyshows He/She can easily grab other framework like Laravel at Geekyshows. I try to make them similar as much as possible.
@@geekyshows yes I know that it's really convenient and easy to understand take this as complement thanks to your hard work I can easily understand the basics of the js
please explain why we reset the inheritance constructor?
Why we reset the inheritance constructor?
Sabse jyada time laga apki iss video ko samghne ar cover karne me..........but maja ayya
Sir please tell me why we are reset constructor ?
because by default prototype object has 2 fields. one is constructor and second is prototype. but for this line "Lenovo.prototype = Object.create(Mobile.prototype);" we override the prototype object and now it has not second field called constructor. so that's why we need to reset the constructor. and need to put this line as well "Lenovo.prototype.constructor = Lenovo;"
sir here i think is a demerit
function extend (child,parent) {
child.prototype = Object.create(parent.prototype);
child.prototype.constructor = child;
} is fine, but when i try to add
child.prototype.anything = function () {
return(this.xyz);
}
and if i try to access this function through the object of its class it shows this function is not defined. why?
Sir , why you make constructor reset ? samsung.prototype.constructor = samsung ..
because by default prototype object has 2 fields. one is constructor and second is prototype. but for this line "Lenovo.prototype = Object.create(Mobile.prototype);" we override the prototype object and now it has not second field called constructor. so that's why we need to reset the constructor. and need to put this line as well "Lenovo.prototype.constructor = Lenovo;"
Very helpful tutorial.
nice explanation
thanks for awesome video but ye smjh nhi aaya k constructor ko reset q krte h, bina reset kiye b work krta h...... please reply
Same problem
Default Behavior Without Reset
• When you use Object.create() to set up inheritance:
Ex. Child.prototype = Object.create(Parent.prototype);
• The prototype of the child is now linked to the parent's prototype.
• However, the constructor property of the child prototype now points to the parent's constructor instead of the child class constructor.
Reset the Constructor?
• Manually reset Child.prototype.constructor to Child to ensure instances of Child correctly identify their constructor.
Ex. Child.prototype.constructor = Child;
If you don’t reset the constructor, checking instance.constructor could give wrong results.
For example, if you want to check if an object is an instance of a certain class, it might mistakenly say it belongs to the parent class.
owsm sir g very helpful to learn
Mera work nahi ho raha inherent function
Why we need reset constructor in inheritance?
because by default prototype object has 2 fields. one is constructor and second is prototype. but for this line "Lenovo.prototype = Object.create(Mobile.prototype);" we override the prototype object and now it has not second field called constructor. so that's why we need to reset the constructor. and need to put this line as well "Lenovo.prototype.constructor = Lenovo;"
Well described
sir agr super class k prototype k method me koi argument de na ho tw kese de ge
You are great.
but how can I memorize those code? what should I do for that?
When you do big projects then you'll remember it automatically. Just practice, practice, practice.
Sir iske baare mei batao plzz constructor reset kyu krte hai???
Sir recursion k liye video hai, please reply?
bro aap ES6 ka use nehi kar rahe ho...getter, setter etc ka bhi use nehi kar rahe
what is the use of call(this)?..by this also we r accessing other members?
accotding to c++ when access to funtion member that time we need to call it thas why we are using here some concept here but i am not sure
@@raeesh2373 java karani chahiye yaa cpp
why reset the constructor ??
because by default prototype object has 2 fields. one is constructor and second is prototype. but for this line "Lenovo.prototype = Object.create(Mobile.prototype);" we override the prototype object and now it has not second field called constructor. so that's why we need to reset the constructor. and need to put this line as well "Lenovo.prototype.constructor = Lenovo;"
Bhiya hmlog constructor kyu reset krte h iski kya jrurat h ??
*Samsung.prototype.constructor = Samsung;*
Line kyu likhte hai sir? uski kya jarurat hai? usse code me kya effect hoga?
Reset constructor
Is code se constructor ko reset krte h
@@johncena-qo2hq thanks John cena.😊👍
sir plz its your first video out of 86 that is a little confusing plz sir make a video again on this topic
why we are using constructor reset ?? alert("plz any one can clear my doubt")
because by default prototype object has 2 fields. one is constructor and second is prototype. but for this line "Lenovo.prototype = Object.create(Mobile.prototype);" we override the prototype object and now it has not second field called constructor. so that's why we need to reset the constructor. and need to put this line as well "Lenovo.prototype.constructor = Lenovo;"
// class
var Mobile=function (){
};
// prtotype method
Mobile.prototype.getModel=function(){ return this.model;}
var mob=new Mobile();
document.write(mob.getModel());
sir mujhe yahi par parameter deke model print karana ho to sir hum karenge, sir please help and reply to me
i can do this also
Object.call(Mobile());
Why getmodule ?????
Ye function h getModel() nam se yeha hum koi b namm rakh sakte h jaise ur name is anish to...getAnish()...etc
confusing
You are too predictable now I guess your object name without seeing
It will help to understand the concept easily. I also follow one pattern to explain various languages and frameworks so if A Person learns Django at Geekyshows He/She can easily grab other framework like Laravel at Geekyshows. I try to make them similar as much as possible.
@@geekyshows yes I know that it's really convenient and easy to understand take this as complement thanks to your hard work I can easily understand the basics of the js