+ 2

Help me understand the workings of methods in JS

I carry out the task in which it is specified to create an object and within it 2 methods. In each method, output a string. All need to do is to execute this code:  obj.method1().method2()  

15th Mar 2018, 9:40 AM
Ashoka Tano
Ashoka Tano - avatar
1 Respuesta
+ 12
function clas() { this.method1 = function() { console.log("method1"); return this; }; this.method2 = function() { console.log("method2"); return this; }; } //clas var obj = new clas(); obj.method1().method2();
15th Mar 2018, 9:48 AM
Valen.H. ~
Valen.H. ~ - avatar