React udemy notes - mosinn/DOCS-n-Snippets-n-Steps GitHub Wiki

  • To write a Class in js, start to write exact as in java, even func impl and instantiation using new of objects, then just remove
  • visibility mods/return types/types in var declaration as we just use const
  • constructor name is constructor (Its only needed in ES6. In ES7, like java, we simply have type less member name and value;)
  • dont attempt to declare traditional member variables, instead use constructor and this.x inside
  • no visibility mods like public/private
  • Var assignment is not against types like MyClass cc = new Myclass; but only against const cc = new MyClass();
  • no use of key words like return, static, final, even let, const etc inside class is allowed.
  • Only key key-words visible in class are class/extends/import outside, then ()/{}/=/; inside
  • while ES6 is very very similar to Java class except we remove key words and member vars are declared using this. inside constr, in ES7, is more even more like java as even member vars can be declared without constr, however, all funcs are declared as lamda style, to give benefit of 'this' context preservence, so class My{ myvar=1; myFunc = () => {console.log('hey:'+this.myvar);} }
  • let and const are new var in js
  • let = var, const = never changing constant values
  • arrow func is like lambda only -> is here => eg const mylambda = ?
  • const mylambda = (x,y) => return xy; OR const mylambda = (x,y) => xy ;
  • Because normal x = y way of copy is copy pointer (like java) in JS, to avoid mutability issues across pointers, best use ... spread operator like say Pers={name=max} ; Per2 = {...Pers}; pers.name=newName; Still Per2.name will be max