Answers for "can you make a class in a class in javascript"

9

create element javascript with class

// create div element by javascript with class

var div = document.createElement('div');
div.className = "div1";
Posted by: Guest on June-15-2020
1

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();
Posted by: Guest on December-16-2021

Code answers related to "can you make a class in a class in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language