Any reason why at 5:45, array.map() method isn't used when using the other ES6 methods?
@djvesko7 жыл бұрын
Great lesson for JS newbies and great reminder for me.
@ZarateAdriel7 жыл бұрын
the copy / assignation in arrays and objects that doesn't happen in strings and number, is about mutability ?
@ZarateAdriel7 жыл бұрын
What about for in? I just note that isn't a deep object copy, but works well for arrays
@bokisa0077 жыл бұрын
very useful, just wanted to add that when using Object.assign, one can add desired properties directly inside of its first param, instead of making it an empty obj and using 3rd to add params. For example: Object.assign({}, wes, {age:26}) can be done like this: Object.assign({age:26}, wes)
@cagmz6 жыл бұрын
Using an empty object for the first param is the correct approach. The way I think of Object.assign is that it does a left-to-right composition of objects. That is, it when called with an empty object as the first param, it merges the `wes` object into the empty object producing a temporary object, and then it merges { age: 26 } into that object. If you use the "desired properties" as the first param, any matching properties from the second param will overwrite those in the first param. Example: > const wes = { age: 27 }; undefined > wes {age: 27} > Object.assign({age:26}, wes) {age: 27} // expected 26
@ericmcgrath25147 жыл бұрын
Welcome back Wes
@WesBos7 жыл бұрын
thanks!
@Suneriins2344 жыл бұрын
Thanks.I learn so many things.
6 жыл бұрын
All those methods of copying arrays make shallow copies. For example: let ar1 = [1,2,3,['a','b','c'],5,6]; let ar2 = ar1.slice(); ar2[3][1] = "BOO!" console.log(ar1); // :( In order to make deep copies, one needs to make a recursive function, for example: function copyArray(arr) { let copy; if (null == arr || "object" != typeof arr) return arr; if (arr instanceof Array) { copy = []; for (const item of arr) { copy.push(copyArray(item)); } return copy; } throw new Error("Unexpected data type"); }
@mriduljain19816 ай бұрын
bro would be happy to know that object spread do exists now
@kisanb7 жыл бұрын
Wes, const cap3 ={...person}; worked for me...
@WesBos7 жыл бұрын
It's in Chrome now!
@rammyramkumar7 жыл бұрын
What is the editor and font you use ?
@WesBos7 жыл бұрын
Yuuup
@hibritusta26424 жыл бұрын
Thanks
@ClevertonHeusner4 жыл бұрын
It's insane.
@furqanashraf56384 жыл бұрын
how bout new keyword
@forgettd7 жыл бұрын
Poppy and Lux. Hm...
@kissu_io7 жыл бұрын
DEMACIA !
@animeshsingh42904 жыл бұрын
Deep Clone function if anyone needs it function cloneObject(obj) { var clone = {}; for(var i in obj) { if(obj[i] != null && typeof(obj[i])=="object") clone[i] = cloneObject(obj[i]); else clone[i] = obj[i]; } return clone; }