Object.setPrototypeOf() Method : Object Oriented Programming in JavaScript Series - Part 6
Вставка
- Опубліковано 7 сер 2017
- Using Object.setPrototypeOf() method to set one Object Literal's method to another.
Article: techsith.com/object-setprototy... - Наука та технологія
the most lucid series on object oriented JavaScript. thank you for this.
I don't understand who can dislike such video ,,,,, i can say this is one of the best video series i have seen in youtube so far. techsith sir you are doing absolutely awesome work. i have learned a lot from this , such kind of questions i faced couple of time in interviews and got confused , now i m clear , thank you so much sir . one request sir please keep uploading the video related to tricky kind of interview question from javascript.
Shoaib, there are some people who would be hard to please so they would always dislike. I am glad that the rest of the population appreciate enough to like the video :) I have plan to relese more tricky interview question video here and my other channel on interviewnest.
techsith yes sir I have already subscribed that channel . thank you so much for helping us to understand the core concepts.
God bless you sir .
Very nice tutorial. I have learnt too many things from this channel. I have seen many channel on UA-cam but no one is better than this channel. A big thanks to the author.
Best series ever ! 🙏🏻
These videos r so awesome
Hello Hemil, Thanks a lot for putting your best into this series. Your way of explaining things is really amazing. I am quite confident after watching your advance javascript series. Thanks for your efforts.
nice explanation thanks:)
I'm loving this series, friend!
Thanks for watching :)
Thanks
Thank you for the video, just one quick question, what is the difference between Object assign and setPrototypeOf ?
Great effort! As a suggestion, I would spend some time to dig a bit deeper by mentioning the existence of Object.assign() method and pointing the differences.
Because i can achieve the exact same by doing,for example, the following:
Object.assign (camry, toyota); //coping toyota methods into camry
console.log (camry.drive()); // 'driving toyota'
Yes. Object.assign add s that property to the object. while setProtoTypeOf adds to objects prototype by creating a prototype link . I also have tutorial on Object.assign and JavaScript mixins where I am using Object.assign().
Hi techsith, one question does it make sense for a beginner to learn javascript (old and ES6) before diving into angular/react..? Is the syntax similar or is it completely different. Thanks
learn only ES6 if you are beginner before diving into Angular/React. Learn following toppings
- let/const
- Arrow functions
- Spread Operators
- Modules (Import ,export)
- Classes
- Iterators ( for of)
- Closures
- Promises
( I have most of these tutorials available you can check it out )
It's also worth noting that Object.create is preferable performance wise.
Yes that is correct.
@Techsith - Can you please make a video on RXJS and Observer subscriber
awesome tutorials, and nice hair!!!
:) Thanks for watching!
the best tutorial I've ever seen, very well explained, love your work, keep it up!
Is there any plan for another series? I would be interested in useful patterns or cool JavaScript hacks.
I am planning series on svg, canvas, react and angular. Thanks for watching!
Amazing series. Request you to please upload more videos on Javascript deeper concepts and also if you can include HTML CSS Angular1 important concepts
I am building videos on CSS and Angular. Will release in few weeks. Thanks for watching!
hi how to use the method of camry by toyota
let Bat = function(legs, isVegetarian){
/* Mammal.call(this, legs); */
this.legs = legs;
this.isVegetarian = isVegetarian;
};
hi sir, I don't get why you use call instead of using this. If I console.log them I get the same output. Is it only because using Call method will make life easier when the parent constructor is very large? or is there any other reason? Thank you !
haha, i meant to comment on the previous tutorial, auto play took me here XD.
oh in this simple example , you can use what ever but in a complex structure where you need to do proper inheritance you should use parents constructor.
I am new to web development field, and the languages I have studied HTML, CSS, javascript & angular 2 but the company 's are expecting more I don't know what to do now. please help me with the suggestions.
Companies do expect you to know concepts like closure, prototype inheritance and such. I do have a series on all the advance topics. you can look through that . ua-cam.com/play/PL7pEw9n3GkoW5bYOhVAtmJlak3ZK7SaDf.html
Are you applying for a new job?
yes
Good luck with the interviews. I have a tutorial on top 10 interview questions that might help.
thanks i will go through it.
Can anyone please explain the difference!
let camry = Object.create(toyota);
would have done the same. Then why are we using setPrototypeOf()? What is the difference between Object.create() and Object.setPrototypeOf()?
Object.create for function constructor and Object.setPrototypeOf for object literal
@@Techsithtube Thanks :)
Hey bro is there any specific difference between Object.create and serPrototypeof method?
Object.create() is for function constructor and setPrototypeOf is for object literals.
Thanks for your excellent tutorials, but you didn't say a word about this method being avoided because of drastically affecting performance. It is explicitly said on MDN, that using this way is highly discouraged. Your tutorials are excellent since you provide a very clear explanation, but can you include a little bit more context so we constantly accumulate an understanding of how these things work in real life?
Thanks for the information. When I created this video which was more than a year ago, this information was not available.
@@Techsithtube Oh, so it's only a recent feature! I was unaware of that.
Yes it was introduced in ES6.
Isn't the same can be achieved using Object.create() ?
Object.create is for functions Object.setProtoTypeOf is for Object literals.
Pl Newbie i m:
let toyota = {
drive(sound) {
console.log(this.sound);
}
}
console.dir(toyota.drive('driving toyota')); returns undefined because it not return anything. can we create object ie..
var camry = new toyota();
camry.drive('driving camry');
Please explain, sincerely
here toyota is a object literal so you can create an object from it. You need a constructor. Please watch this series to understand more ua-cam.com/play/PL7pEw9n3GkoW0ceMeoycg9D00YjPAbtvt.html
function Human(){
this.fullName = "Riyad" ;
}
Human.prototype.getFullName = function(){
console.log(this.fullName) ;
}
let riyad = {}
Object.setPrototypeOf(riyad, Human);
console.log(riyad.__proto__ === Human.prototype) // why false ??
console.log(riyad.getFullName() ); // why not working ?