zoukankan      html  css  js  c++  java
  • 代码类面试题

    1.this的指向

    
    

    function Cat (name) {

        this.name = name;

    }

    Cat.prototype.sayCatName = () => {

        console.log(this === window);

        return this.name;

    };

    
    

    const cat = new Cat('Miao');

    
    

    cat.sayCatName();

     
    //结果为:true

    2.let和var定义变量

    for (var i = 0; i < 3; i++) {
     setTimeout(() => console.log(i), 1);
    }
    for (let i = 0; i < 3; i++) {
     setTimeout(() => console.log(i), 1);
    }
    //结果
    3 3 3
    0 1 2

    3.对象的引用的是对象的地址

    let c = { greeting: "Hey!" };
    let d;
    d = c;
    c.greeting = "Hello";
    console.log(d.greeting);
    //结果:
    hello

    4.this在箭头函数中的指向

    function Person(firstName, lastName) {
     this.firstName = firstName;
     this.lastName = lastName;
    }
    const member = new Person("Lydia", "Hallie");
    Person.getFullName = () => this.firstName + this.lastName;
    
    console.log(member.getFullName());
    //结果
    member.getFullName is not a function
        at <anonymous>:8:20
    报错该对象没有这个方法

    5.对象进行===时的情况

    function checkAge(data) {
     if (data === { age: 18 }) {
     console.log("You are an adult!");
     } else if (data == { age: 18 }) {
     console.log("You are still an adult.");
     } else {
     console.log(`Hmm.. You don't have an age I guess`);
     }
    }
    checkAge({ age: 18 });
    //结果:You don't have an age I guess
    进入了else
    勤学似春起之苗,不见其增,日有所长; 辍学如磨刀之石,不见其损,日所有亏!
  • 相关阅读:
    mysql备份与还原
    mysql基本操作
    mysql权限管理
    linux下mysql-5.5.15安装详细步骤
    mongo长连接
    css rem计算
    yii2使用小知识(连续补充)
    自动化运维工具ansible部署以及使用
    测试docker不同主机间容器互相访问
    redis慢查询日志
  • 原文地址:https://www.cnblogs.com/qiaozhiming123/p/14710884.html
Copyright © 2011-2022 走看看