• JS 函数—length & prototype


     JS中的函数也是对象,因此有属性和方法。每个函数都有两个属性:length和prototype。

    ①length属性保存函数定义的命名参数的个数,如下:

     1     function sayName(name){
     2         console.log(name);
     3     }
     4 
     5     function sayHi(){
     6         console.log("Hi");
     7     }
     8 
     9     function sum(n,m){
    10         return n+m
    11     }
    12 
    13     console.log(sayName.length); // 1
    14     console.log(sayHi.length);  // 0
    15     console.log(sum.length);  // 2

     ②prototype属性保存引用类型所有实例方法的地方,这意味着toString()、valueOf()等方法实际上都保存在prototype上,进而由所有实例共享。

  • 相关阅读:
    Python-05 基础语法-函数
    使用单个命令安装 WSL 现在可在 Windows 10 版本 2004 及更高版本中使用
    java.sql public interface ResultSet
    Selecting Contents for Uber JAR
    【初次使用h0遇到的一些问题】
    关于Swagger-UI下的渗透实战
    CTF—MISC—USB键盘流量分析
    k8s之路-Rancher
    单元测试
    flutter开发中设置模拟器一直悬浮在ide上方
  • 原文地址:https://www.cnblogs.com/codexlx/p/14335375.html
Copyright © 2020-2023  润新知