JS Context

Object Methods

  • Methods are actions that can be performed on objects.
  • Object properties can be both primitive values, other objects, and functions.
  • An object method is an object property containing a function definition.

new

Change function context

Class work

Calculator v1

function Calculator(leftOperand){
 // your code
}

var calc = new Calculator(12);
console.log(calc.multiply(2)); //24
console.log(calc.add(3)); //25
console.log(calc.subtract(1)); //11
console.log(calc.divide(2)); //6

Calculator v2

function Calculator(leftOperand) {
	// Your code
}

var calc = new Calculator(12);
alert(calc.multiply(2).add(3)); // 27

Calculator v3

function Calculator(leftOperand){
 // your code
}

var calc = new Calculator(12);

//Various number of arguments
console.log(calc.multiply(2, 2, 4, 5)); 
console.log(calc.add(3, 1, 2)); 
console.log(calc.subtract(1, 4, 2, 1)); 
console.log(calc.divide(2, 6)); 

Home work

https://learn.javascript.ru/objects-more Методы объектов и контекст вызова

https://learn.javascript.ru/js-misc Некоторые другие возможности

THANKS FOR YOUR ATTENTION

JS Context

Made with Slides.com