Javascript 什么';parseFloat(';number';)中发生了什么。是否固定为(2)?
这个方法是怎么回事Javascript 什么';parseFloat(';number';)中发生了什么。是否固定为(2)?,javascript,Javascript,这个方法是怎么回事 parseFloat('123.234').toFixed(2); 如何根据结果创建这样的函数,我们可以调用其他函数?有人能提供这种方法的内部结构吗?这是方法链接吗?这确实是方法链接parseFloat返回一个Number对象,该对象有一个固定的方法 这是一个向您展示其工作原理的基本示例: function Construct(){ this.method1 = function(){ return this; }; this.method2 =
parseFloat('123.234').toFixed(2);
如何根据结果创建这样的函数,我们可以调用其他函数?有人能提供这种方法的内部结构吗?这是方法链接吗?这确实是方法链接
parseFloat
返回一个Number对象
,该对象有一个固定的方法
这是一个向您展示其工作原理的基本示例:
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'
这可能很有趣:这也是:您只需调用parseFloat
返回的结果的toFixed
方法。只要知道返回的是哪种类型的值,就可以访问它的任何属性。例如,我知道getElementById
返回一个DOM节点,所以我可以这样做:var name=document.getElementById('foo.nodeName)代码>。这些方法所做的没有什么特别之处。