• javascript重要类方法笔记


    三、数据结构和map
        1、大括号数据结构:{}
            1.1 键值对形式,类似Map
               1.2 var treeNode={};
                treeNode.label = item[labelField];
                treeNode.id = item[idField];
                treeNode.pid = item[pidField];
                treeNode.children = [];
            1.3 var treeIndex = {};
                treeIndex['01']=treeNode;        
        2、中括号数据结构:[]
            2.1 数组
            2.2 treeNode.children = [];
                treeNode.children.psuh(treeNode1) //添加一个数据

     3、遍历

          var testMap = {};
          for(var n=0; n<5; n++){
            var item = {};
            item.id = n;
            item.description = 'aaa' + n;
            item.age = n + 10;
            testMap[item.description] = item;
          }
          for(var k in testMap){
            console.log('testMap===', testMap[k]);
          }

    五、map对象和{}定义的对象
        可以使用delete 删除一个元素,例:
               var treeNode={};
            treeNode.label = item[labelField];
            treeNode.id = item[idField];
            treeNode.pid = item[pidField];
            treeNode.children = [];    
            delete treeNode['children']; //删除children数值对象
            
            delete map[key]; // map.remove(key);

    六、数值需要给元素一个属性,直接定义
        arrtmp[3].tmpProp = 'sdfsdfs';


              this.tradeArr.forEach(funtion(tradeArrItem){
                 if (tradeArrItem.description == sectionLable){
                    this.supplyBqItemRec.tradeCode = tradeArrItem.code;
                 };
              });

    一、数据类型
        1、map
           1.1 定义:map1={x:1,y:2,z:3}
           1.2 访问1:map1.x..
               访问2:map1['x']
           1.3 函数返回:return {x:1,y:2,z:3}
           1.4 属于对象,引用属于指针引用
        2、数组
           2.1 定义 var sz1=[1,2,3,'foot',s,{x:1,y:2},[3,4,5]]
           2.2 访问 sz1[index]
    二、句型
        1、for
           for{var n=0;n<10;n++}{
             ...
           }    
        2、forin
           var obj = {x:1, y:3, z:2}
           for (var v in obj){
              print(v)
           }
           //代码输出结果:x,y,z
        3、foreachin
           var obj = {x:1, y:3, z:2}
           for each (var v in obj){
              print(v)
           }
           //代码输出结果:1,2,3
        4、switch (语句){
           case 表达式1:
               语句
               语句
               ....
           case 表达式1:
               语句
               语句
               ....
           default :
               语句
               语句
               ....           
           }   
    三、对象
        1、对象的更改方式
           Object.preventExtensions() //无法新增属性值,可以删除属性
           Object.seal() //无法删除属性,可以更高属性值
           Object.freeze() //无法更改属性值
        2、this引用规则
           2.1 通过运算符或中括号运算符调用对象的方法时,在运算符左侧制定的对象
           2.2 apply和call:指定接受对象,this的参数从指定的接受对象中提取

  • 相关阅读:
    汇编 Hello Window [菜鸟]疑问
    得到指定进程所有窗口。显示 影藏 置顶。
    汇编,SendMessage和WM_SETTEXT
    C#: 字段和局部变量的作用域冲突
    C#: 给方法传递参数
    C#:类和结构
    C#: string 类型
    Copy files to a folder which need have Administrator approve and overwrite the existing same readonly files
    C#:构造函数
    C#:数组, 命名空间, Main()方法
  • 原文地址:https://www.cnblogs.com/SouthAurora/p/8550971.html
Copyright © 2020-2023  润新知