Object.assign() Method : Object Oriented Programming in JavaScript Series - Part 7

Поділитися
Вставка

КОМЕНТАРІ • 46

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

    Very well explained! No nonsense and just straight to the point. Thank you sir!

  • @HakanGalip
    @HakanGalip Рік тому

    Thanks a lot for this wonderful series.

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

    Great tutorials! Thank you so much!!!!

  • @velmurugan-jo3vb
    @velmurugan-jo3vb 6 років тому

    I spend more time in your channel and i suggest to all my colleague about your channel...Thanks man...

  • @shivam96sa
    @shivam96sa 3 роки тому

    making javascript easy.
    learning by examples approach instead of raw theory makes is far better.
    excellent content.

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

    techsith you are awesome! Thank you!

  • @dubeykivines9202
    @dubeykivines9202 4 роки тому +1

    Wow nice one

  • @garrettbaker2320
    @garrettbaker2320 7 років тому +3

    Very informative series..thanks!

  • @anaghasalvi8364
    @anaghasalvi8364 4 роки тому

    Very useful.Thank you

  • @tomcarbon3562
    @tomcarbon3562 4 роки тому

    excellent. Thank You

  • @joshrochon6243
    @joshrochon6243 6 років тому +3

    Hey so instead of Toyota you should give the break() method to Ford

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

    u r the champ of JS

  • @abhiabhang9938
    @abhiabhang9938 7 років тому

    Hey genius, I implement it ,Its work fine ,Thanks for sharing the videoes.

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

    Very Useful

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

    till this video I found the tutorials quite in-depth and easy to understand. Thanks for all your effort and time.
    do you have any html5 and reactjs tutorial ?

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

    Didn't you forget a return statement in the last function?

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

    Hi, first of all, I am very thankful for your tutorials, but I am little bit confused about shallow copy explanation. As I know, shallow means not copy of object , it means sharing same local memory and has same reference, so if you change one of them object, other one will be affected. But if you copy object with Object.assign and then you add new method or property to object, the other object will not be affected.
    It is like Deep Copy, isn't it?

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

      Shallow copy means copy one level down . so if you have an deeply nested object. after one level down you are just referencing the object not copying.

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

      @@Techsithtube , I’m struggling with the concept of deep/shallow copy as well, let me make sure that I got this completely clearly: object.assign copies properties from one object literal to another; It does so in a manner of FULL COPY or CLONE so two objects are independent and you can change one object ant this change will not affect the other object; UNLESS you are copying object’s properties that are MORE THAN ONE LAYER DEEP in which case deeper proprties will be passed by reference, they will have a common source and changing one object will result in changing both. Is everything correct in this description?

    • @saeeduchiha5537
      @saeeduchiha5537 3 роки тому

      @@egorsmirnov452 one-level copy means only primitive data types will be deep-copied. The composite (none primitive) data types (e.g arrays and objects) are shallow-copied (aka by pointer/reference only)

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

    Is it a good practice to use Object.assign method in constructor?

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

      As long as your bowser supports Object.assign you should use it .

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

    Hello, you said that prototype methods don't get copied but I tried the below code and type() method is in both objects, vitz and toyota.
    Why is that so? It should not be present in vitz object, right?
    let toyota = {
    drive() {
    return 'driving toyota';
    }
    };
    toyota.prototype = {
    type() {
    return 'Sedan';
    }
    }
    let vitz = Object.assign({}, toyota);
    console.dir(vitz);
    console.dir(toyota);

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

      what you see is an illusion you cant add the prototype to an object literal like this. its meant for constructors (functions) . the right syntax would be
      let toyota = {
      drive() {
      return 'driving toyota';
      }
      };
      Object.setPrototypeOf(toyota, {
      type: function() {
      return 'Sedan';
      }
      })
      let vitz = Object.assign({}, toyota);
      console.dir(vitz);
      console.dir(toyota);

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

      Oh yes, Thank you so much for pointing out the mistake and clearing the concept.

  • @biikaaa.6540
    @biikaaa.6540 3 роки тому

    i dont understand the last part

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

    Can u pls exaplain shallow and deep copy in little detail?

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

      Shallow means a copy of the object and its methods. a deep copy will include not only object data but its prototype properties as well. got it?

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

      yes got ..thanku so much

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

    I thought in objects it needed to be drive: function(){},

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

      in the ES6/ES2015 you can use drive(){}

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

      techsith thanks

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

    Is this advanced JAVASCRIPT

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

      it's not advance javaScript. but most of the people don't use it.

  • @baturalkan2959
    @baturalkan2959 3 роки тому

    4:00 , actually Object.assign() doesnt make the shallow copy, instead makes the deep copy with below exception, please check this MDN example;
    (If the source value is a reference to an object, it only copies the reference value.)
    let obj1 = { a: 0 , b: { c: 0}};
    let obj2 = Object.assign({}, obj1);
    console.log(JSON.stringify(obj2)); // { "a": 0, "b": { "c": 0}}
    obj1.a = 1;
    console.log(JSON.stringify(obj1)); // { "a": 1, "b": { "c": 0}}
    console.log(JSON.stringify(obj2)); // { "a": 0, "b": { "c": 0}}
    obj2.a = 2;
    console.log(JSON.stringify(obj1)); // { "a": 1, "b": { "c": 0}}
    console.log(JSON.stringify(obj2)); // { "a": 2, "b": { "c": 0}}
    obj2.b.c = 3;
    console.log(JSON.stringify(obj1)); // { "a": 1, "b": { "c": 3}}
    console.log(JSON.stringify(obj2)); // { "a": 2, "b": { "c": 3}}

    • @Techsithtube
      @Techsithtube  3 роки тому

      That is consider as a shallow copy. THat is why your last example has the same C value. Deep copy will create copy of everything.

    • @baturalkan2959
      @baturalkan2959 3 роки тому

      @@Techsithtube Shallow copy of every prop individually not the obj itself, got you thanks

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

    check this out..
    object.assign( [ ], obj ). Magic :). Not a shallow copy right? Or am i just writing rubbish?