资讯详情

《Javascript高级程序设计(第4版)》问题

Javascript高级程序设计(第4版)QS

    • 1. P28 let作为for循环变量
    • 2. P42 模板字面量标签函数
    • 3. P53 Symbol.species
    • 4. P95 标记清理
    • 5. P104 GMT日期/本地日期
    • 6. P112 正则表达式
    • 7. P114 工厂方法
    • 8. P127
    • 9. js所有参数的传递都是传值
    • 10. P177 返回集合的幂集
    • 11. P295 apply(null, )
    • 12. P313 赋值表达式的值是函数本身,this不再与任何对象绑定
    • 13. P648 腻子脚本
    • 14. 未见:定型数组P158-163、20.12、C27,C28

过了一个星期的基本内容,太陌生了/基本上跳过了关于底层的内容,记录下看起来不懂的地方。

1. P28 let作为for循环变量

https://segmentfault.com/a/1190000040163287 https://wesbos.com/for-of-es6

2. P42 模板字面量标签函数

标签函数中strings对应一个数组,开头和结尾的元素要么是空字符串,要么是开头和结果的符号。

let a = 1; let b = 2; let c = 3; function simpleTag(strings, ...expressions) { 
             console.log(strings);      for (const expression of expressions) { 
                 console.log(expression);     }     return 'foobar'; }  let untaggedResult = `@ ${ 
          a} ${ 
          b} ${ 
          c} = ${ 
          a   b   c} !`; let taggedResult = simpleTag`@ ${ 
          a} ${ 
          b} +${ 
          c} = ${ 
          a + b + c}+!`;
// ['1+', ' + ', ' +', ' = ', '+!', raw: Array(5)]
// 1
// 2
// 3
//6
console.log(untaggedResult);// "@+1 + 2 +3 = 6+!"
console.log(taggedResult);// "foobar"

3. P53 Symbol.species

调用get后,覆盖创新实例的原型定义

class geek extends Array { 
        
    static get [Symbol.species]() { 
        
        return Array;
    }
}

// Values assigned to geek
const a = new geek(1, 2, 3, 4);

console.log(a instanceof geek);
// output:true

console.log(a instanceof Array);
// output:true

//mapped values to geek object
const mapped = a.map((x) => 2);

console.log(mapped instanceof geek);
// output:false

console.log(mapped instanceof Array);
  // output:true

4. P95 标记清理

进入和离开环境都会被标记

5. P104 GMT日期/本地日期

本地时间是指你的计算机所在的时区 格林威治标准时间GMT

6. P112 正则表达式

  1. /(…)or(.)/ :(.)匹配任意一个字符,(…)匹配任意三个字符
  2. 捕获组: https://www.runoob.com/w3cnote/java-capture-group.html

7. P114 工厂方法

传入不同的参数,得到不同的产品 https://blog.csdn.net/qq_42543177/article/details/124600274

8. P127

.split(/[^,]+/),表示以非逗号分隔 返回数组前后两个空字符串,是正则表达式指定分隔符出现在字符串开头red和结尾yellow https://segmentfault.com/q/1010000005268466

9. js所有参数传递都是传值

对于对象等引用数据类型,“=”操作会覆盖掉原来的地址值。 https://segmentfault.com/a/1190000020519770

var student = new Object()

function addName(obj) { 
        
    obj.name = "zhang";

    obj = { 
        };   //或者任何重新为obj赋值的操作,如 obj = new Object();
    obj.name = "lisi";
    console.log("obj.name: " + obj.name);//lisi
}

addName(student)
console.log("student.name: " + student.name);//zhang
var student = new Object()

function addName(obj) { 
        
    obj.name = "zhang";

    //obj = {}; //或者任何重新为obj赋值的操作,如 obj = new Object();
    obj.name = "lisi";
    console.log("obj.name: " + obj.name);//lisi
}

addName(student)
console.log("student.name: " + student.name);//lisi

10. P177 返回集合的幂集

类似于:https://blog.csdn.net/m0_46612221/article/details/122703114

function powerSet(a) { 
        
    const powerSet = new Set().add(new Set());
    //Set(1) {size: 1, Set(0) {…}}, 相当于[[]]
    console.log(powerSet);
    for (const aVal of a) { 
        
        for (const set of new Set(powerSet)) { 
        
            console.log(set);//Set
            powerSet.add(new Set(set).add(aVal));
        }
    }
    return powerSet;
}

powerSet(new Set([1, 2, 3]));

11. P295 apply(null, )

由于 JavaScript 数组没有 max() 方法,因此可以应用 Math.max() 方法。

Math.max.apply(, [1,2,3]); // 返回 3

12. P313 赋值表达式的值是函数本身,this不再与任何对象绑定

https://zhidao.baidu.com/question/509255245.html 在这里插入图片描述

object.getName=object.getName赋值表达式,返回的是object.getName指向的那个函数,直接对赋值表达式的结果进行调用就等于是在全局作用域中调用了一个函数,此时函数中的this就指向全局作用域变量,所以此时this不能维持

13. P648 腻子脚本

https://blog.csdn.net/houweb2/article/details/51509030

14. 未看:定型数组P158-163、20.12、C27,C28

标签: p28j4mj密封连接器

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

 锐单商城 - 一站式电子元器件采购平台  

 深圳锐单电子有限公司