Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

method chaining in javascript


class Arithmetic {
  constructor() {
    this.value = 0;
  }
  sum(...args) {
    this.value = args.reduce((sum, current) => sum + current, 0);
    return this;
  }
  add(value) {
    this.value = this.value + value;
    return this;
  }
  subtract(value) {
    this.value = this.value - value;
    return this;
  }
  average(...args) {
    this.value = args.length
      ? (this.sum(...args).value) / args.length
      : undefined;
    return this;
  }
}

a = new Arithmetic()
a.sum(1, 3, 6)   // => { value: 10 } 
  .subtract(3)   // => { value: 7 }
  .add(4)        // => { value: 11 }
  .value         // => 11 

// Console Output
// 11
Comment

method chaining

given() ....   --> RequestSpecification 
     .header  accept() contentType()
     .queryParam
     .pathParam
     .body
     .log
     .auth..
when()       --->> RequestSender
   .get() ------>> Response Object 
   .post()
   .put()
   .delete()
then()      -----> ValidatableResponse  
        This is where assertion happen 
    .statusCode
    .header   accept() contentType()
    .body( matchers goes here)
    .log
Comment

Method Chaining

String methods can be combined in a process called method chaining. 
Given word = 'JavaScript';, word.toUpperCase() returns JAVASCRIPT. 
What would word.slice(4).toUpperCase() return?
Comment

PREVIOUS NEXT
Code Example
Javascript :: on scroll call function jquery 
Javascript :: instalar bootstrap en react 
Javascript :: clear input field data in jquery 
Javascript :: react-native-community/blur 
Javascript :: tableau js 
Javascript :: remove the first item from an array 
Javascript :: react router remove location state on refresh 
Javascript :: Sequelize.Op; 
Javascript :: wait for 1 second in loop in javascript 
Javascript :: last item in array javascript 
Javascript :: angular disable select dropdown 
Javascript :: react arrow function component 
Javascript :: getting data from an api 
Javascript :: javascript deconstruct object 
Javascript :: jquery: finding all the elements containing the text present in an array 
Javascript :: how to use if else inside jsx in react 
Javascript :: Appending the option element using jquery each function 
Javascript :: Angular empty object 
Javascript :: vue js hooks 
Javascript :: javascript object lookups 
Javascript :: render first index active tabs in reactjs 
Javascript :: react bootstrap table 
Javascript :: plotly express bar graph 
Javascript :: how to get current date in express js 
Javascript :: check if all elements in array match a condition javascript 
Javascript :: moment all formats in reactjs 
Javascript :: how to make button in react js 
Javascript :: format string javascript 
Javascript :: append raw html javascript 
Javascript :: switch react router 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =