zoukankan      html  css  js  c++  java
  • in操作符

    // Arrays,数组:下标 in array,length也可以

    var trees = new Array("redwood", "bay", "cedar", "oak", "maple");

    0 in trees        // returns true

    3 in trees        // returns true

    6 in trees        // returns false

    "bay" in trees    // returns false (you must specify the 

                      // index number, not the value at that index)

    "length" in trees // returns true (length is an Array property)

     

    // Predefined objects:内置对象

    "PI" in Math          // returns true

     

    // Custom objects:对象,key in obj

    var mycar = {make: "Honda", model: "Accord", year: 1998};

    "make" in mycar  // returns true

    "model" in mycar // returns true

     

    //使用字符串对象构造的

    var color1 = new String("green");

    "length" in color1 // returns true 

    //string不会使用构造函数转换

    var color2 = "coral";

    // generates an error (color2 is not a String object)

    "length" in color2

     

    //delete之后,就false了

    var mycar = {make: "Honda", model: "Accord", year: 1998};

    delete mycar.make;

    "make" in mycar;  // returns false 

    var trees = new Array("redwood", "bay", "cedar", "oak", "maple");

    delete trees[3];

    3 in trees; // returns false

     

    //设为undefined的话,就false

    var mycar = {make: "Honda", model: "Accord", year: 1998};

    mycar.make = undefined;

    "make" in mycar;  // returns true 

    var trees = new Array("redwood", "bay", "cedar", "oak", "maple");

    trees[3] = undefined;

    3 in trees; // returns true

     

    //可以找到原型链的key

    "toString" in {}; // returns true

  • 相关阅读:
    烂泥:jira7.2安装、中文及破解
    烂泥:VMWare Workation双网卡配置IP地址
    烂泥:centos6 yum方式升级内核
    烂泥:python2.7和python3.5源码安装
    烂泥:zabbix3.0安装与配置
    烂泥:利用awstats分析nginx日志
    烂泥:切割nginx日志
    JavaScript之函数
    Django之根据已经存在数据库中的表自动生成模型
    Django之操作数据库
  • 原文地址:https://www.cnblogs.com/wang-jing/p/4736436.html
Copyright © 2011-2022 走看看