Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 什么';parseFloat(';number';)中发生了什么。是否固定为(2)?_Javascript - Fatal编程技术网

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)。这些方法所做的没有什么特别之处。