What happens in parseFloat ('number'). toFixed (2)?

What happens in this method

parseFloat('123.234').toFixed(2); 

How to create such functions, by the results of which we can name other functions? Can someone provide the internal structure of such methods? Is this method a chain?

+4
source share
1 answer

This is really a chain of methods. parseFloat returns a Number object that has a toFixed method.

This is a basic example showing how it works:

 function Construct(){ this.method1 = function(){ return this; }; this.method2 = function(){ alert('called method2'); return this; }; this.method3 = function(){ alert('method3: I am not chainable'); }; } var instance = new Construct; instance.method1().method2().method3(); //=> alerts 'called method2' and 'method3: I am not chainable' 
+4
source

All Articles