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上,进而由所有实例共享。

  • 相关阅读:
    Python环境搭建-anaconda
    UITableView的基本使用方法
    模拟网易新闻上方滚动条
    iOS之导航栏基本设置
    UITextField 方法和代理的使用
    UITextField详解
    init方法的重写与自定义
    OC中协议的理解protocal
    IOS中检测键盘出现和消失的消息
    怎么重装系统(一)
  • 原文地址:https://www.cnblogs.com/codexlx/p/14335375.html
Copyright © 2011-2022 走看看