Day86 of #100Daysof Code :::: JavaScript Class Expressions.
Classes can be found in a function. A lot can be done with them there. For instance, a class in a function can be passed around, returned and can be found inside another expression.
Lets take a look at a functionn that returns a class
function createClass( word ){
//return a class after a creating it
return class{
greeting(){
console.log( word )
};
};
}
let Developer = createClass("New class");
new Developer().greeting() //"New Class"
The above function created and returned a class. We can create and return multiple functions in a class.
function createClass( word,word1 ){
//return a class after a creating it
return class{
greeting(){
console.log( word )
};
greeting1(){
console.log( word1 )
};
};
}
let Developer = createClass("New class", "second class");
new Developer().greeting() //"New Class"
new Developer().greeting1() //"second Class"
In this one we created and returned two methods in the class created with a function.