Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Javascript Class Methods

// constructor function
function Person (name) {

   // assigning  parameter values to the calling object
    this.name = name;

    // defining method
    this.greet = function () {
        return ('Hello' + ' ' + this.name);
    }
}
Comment

js class syntax

// method 1

function nested(name , age , color){
    this.name = name;
    this.details = { 
        age : age,
        color : color
    }
}

let nestedObj = new nested( "Elroi" , 22 , "blue");
 console.log(nestedObj)


// method 2
class Nested2{
    constructor(name , age , color){
        this.name = name;
        this.details = {
            age : age,
            color : color
        }
    };

    displayInfo(){
        console.log(`${this.name} ${this.details.age} ${this.details.color} `)
    } 
}

let aaa  = new Nested2("Ean" , 14 , "black");
aaa.displayInfo(); 
Comment

this in js class method

function add(c, d) {
  return this.a + this.b + c + d;
}

var o = {a: 1, b: 3};

// The first parameter is the object to use as
// 'this', subsequent parameters are passed as
// arguments in the function call
add.call(o, 5, 7); // 16

// The first parameter is the object to use as
// 'this', the second is an array whose
// members are used as the arguments in the function call
add.apply(o, [10, 20]); // 34
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to minimize electron app to tray icon 
Javascript :: what is functional composition 
Javascript :: json stringify double quotes 
Javascript :: use setstate in function component 
Javascript :: export table data to excel in jquery 
Javascript :: Using Regular Expressions (regex) to Print JavaScript Number Format with Commas 
Javascript :: how to play audio in javascript 
Javascript :: Difference in push and navigate in react Navigation 
Javascript :: for each loop with arrowfunction 
Javascript :: axios delete with data 
Javascript :: check object is null empty or undefined 
Javascript :: modulo operator in javascript 
Javascript :: javascript array.find 
Javascript :: run a local instance of Kibana on docker and connect to elasticsearch 
Javascript :: discord.js guildMemberRemove 
Javascript :: usecallback vs usememo 
Javascript :: mysql json_array_append 
Javascript :: write to file but dont overwrite fs.writeFile node 
Javascript :: javascript copy div element content 
Javascript :: clear element children js 
Javascript :: create select option using jquery 
Javascript :: change property in array of objects javascript 
Javascript :: image react native 
Javascript :: javascript concat two arrays 
Javascript :: React Native Starting In Android 
Javascript :: flatmap javascript 
Javascript :: console.log json shopify 
Javascript :: A simple static file server built with Node.js 
Javascript :: javascript filter array of objects by array 
Javascript :: how to redirect to a website in react 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =