JS OOP - Ahmed-Ayman/My-2017-Vacation GitHub Wiki

Declaring JS object.

the handy way.

 var Car = {
  wheels : 4,
  engines :1,
  seats : 5
};

constructor

var Car = function() {
  this.wheels = 4;
  this.engines = 1;
  this.seats = 5;
};

var hunday = new Car(); hunday.company="hunday"

private props


var Bike = function() {
// private prop
  var gear;
  
  this.setGear = function(gearNumber){
    gear=gearNumber;
  };
  this.getGear= function(){
    return gear;
  };
};
var myBike = new Bike();

then you can pass any args to the function. say I need a custom number of wheels.

iterate over arrays

 
var oldArray = [1,2,3,4,5];
var newArray = oldArray.map(function (x){
  return x+3;
});

accumlation

//the sum of the array elements
singleVal = array.reduce(function(previous,current){
  return prev+current;
});

var oldArray = [1,2,3,4,5,6,7,8,9,10];
//creates a new array with the returned values
var newArray = oldArray.filter(function(x){
  return !(x >5); // 1 2 3 4 5
});

Sort

then it the reverse() ,concat() functions.