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...
  • Наука та технологія

КОМЕНТАРІ • 49

  • @user-zb5jp4ti1d
    @user-zb5jp4ti1d 7 років тому +2

    the most lucid series on object oriented JavaScript. thank you for this.

  • @mdshoaibAlamgcetts
    @mdshoaibAlamgcetts 6 років тому +10

    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.

    • @Techsithtube
      @Techsithtube  6 років тому +5

      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.

    • @mdshoaibAlamgcetts
      @mdshoaibAlamgcetts 6 років тому

      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 .

  • @ramdhenudhunia1507
    @ramdhenudhunia1507 5 років тому

    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.

  • @anonymous.youtuber
    @anonymous.youtuber 4 роки тому

    Best series ever ! 🙏🏻

  • @MylesGmail
    @MylesGmail 5 років тому +1

    These videos r so awesome

  • @Bhanwar-Rathore
    @Bhanwar-Rathore 3 роки тому

    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.

  • @delisandor5337
    @delisandor5337 5 років тому +3

    nice explanation thanks:)

  • @gabrieldefazio
    @gabrieldefazio 6 років тому +2

    I'm loving this series, friend!

  • @seenuvasanv
    @seenuvasanv 6 років тому +1

    Thanks

  • @edgarcheverier
    @edgarcheverier 6 років тому +2

    Thank you for the video, just one quick question, what is the difference between Object assign and setPrototypeOf ?

  • @alexm4121
    @alexm4121 6 років тому +2

    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'

    • @Techsithtube
      @Techsithtube  6 років тому

      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().

  • @DanielWeikert
    @DanielWeikert 6 років тому +2

    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

    • @Techsithtube
      @Techsithtube  6 років тому +2

      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 )

  • @yass-a
    @yass-a 6 років тому +1

    It's also worth noting that Object.create is preferable performance wise.

  • @ruchirai5775
    @ruchirai5775 5 років тому

    @Techsith - Can you please make a video on RXJS and Observer subscriber

  • @emi22n
    @emi22n 7 років тому +2

    awesome tutorials, and nice hair!!!

  • @petrbecka7915
    @petrbecka7915 6 років тому

    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.

    • @Techsithtube
      @Techsithtube  6 років тому +1

      I am planning series on svg, canvas, react and angular. Thanks for watching!

  • @ruchirai5775
    @ruchirai5775 6 років тому +2

    Amazing series. Request you to please upload more videos on Javascript deeper concepts and also if you can include HTML CSS Angular1 important concepts

    • @Techsithtube
      @Techsithtube  6 років тому

      I am building videos on CSS and Angular. Will release in few weeks. Thanks for watching!

  • @jayel5k
    @jayel5k 2 роки тому

    hi how to use the method of camry by toyota

  • @honghulin8810
    @honghulin8810 6 років тому +2

    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 !

    • @honghulin8810
      @honghulin8810 6 років тому +1

      haha, i meant to comment on the previous tutorial, auto play took me here XD.

    • @Techsithtube
      @Techsithtube  6 років тому +2

      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.

  • @girishacharya227
    @girishacharya227 6 років тому +1

    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.

    • @Techsithtube
      @Techsithtube  6 років тому

      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?

    • @girishacharya227
      @girishacharya227 6 років тому

      yes

    • @Techsithtube
      @Techsithtube  6 років тому

      Good luck with the interviews. I have a tutorial on top 10 interview questions that might help.

    • @girishacharya227
      @girishacharya227 6 років тому

      thanks i will go through it.

  • @Atif1702
    @Atif1702 5 років тому +1

    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()?

    • @Techsithtube
      @Techsithtube  5 років тому +2

      Object.create for function constructor and Object.setPrototypeOf for object literal

    • @Atif1702
      @Atif1702 5 років тому

      @@Techsithtube Thanks :)

  • @customdev7078
    @customdev7078 5 років тому

    Hey bro is there any specific difference between Object.create and serPrototypeof method?

    • @Techsithtube
      @Techsithtube  5 років тому

      Object.create() is for function constructor and setPrototypeOf is for object literals.

  • @egorsmirnov452
    @egorsmirnov452 5 років тому

    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?

    • @Techsithtube
      @Techsithtube  5 років тому

      Thanks for the information. When I created this video which was more than a year ago, this information was not available.

    • @egorsmirnov452
      @egorsmirnov452 5 років тому

      @@Techsithtube Oh, so it's only a recent feature! I was unaware of that.

    • @Techsithtube
      @Techsithtube  5 років тому

      Yes it was introduced in ES6.

  • @Amandeepsinghjaura10
    @Amandeepsinghjaura10 5 років тому

    Isn't the same can be achieved using Object.create() ?

    • @Techsithtube
      @Techsithtube  5 років тому

      Object.create is for functions Object.setProtoTypeOf is for Object literals.

  • @sheshtiwari7306
    @sheshtiwari7306 6 років тому

    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

    • @Techsithtube
      @Techsithtube  6 років тому

      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

  • @Tek_Tok777
    @Tek_Tok777 5 років тому

    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 ?