zoukankan      html  css  js  c++  java
  • 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上,进而由所有实例共享。

  • 相关阅读:
    [bzoj1095] [ZJOI2007]Hide 捉迷藏
    [bzoj3730] 震波
    [bzoj3672] [Noi2014]购票
    [bzoj4129] Haruna’s Breakfast
    《CSS3知识点》
    《表单总结》
    <表格>
    《HTML总结》
    <java程序大集合>
    《字符串的概念》
  • 原文地址:https://www.cnblogs.com/codexlx/p/14335375.html
Copyright © 2011-2022 走看看