• 前端面试(题三)js


    1.call、apply及bind的区别

    2.自己实现instanceof (考点:原型链;递归)

     3.自己实现new (考点:JS对象的实现化;原型链)

     5.判断一个数据的类型

    ①. toString.call()

     ②. typeof

     6. js深拷贝

    function deepCopy (source) {
        var target = Array.isArray(source) ? [] : {};
        for (let key in source) {
            if (source.hasOwnProperty(key)) {
                if (typeof source[key] === 'object') {
                    target[key] = deepCopy(source[key]);
                } else {
                    target[key] = source[key];
                }
            }
        }
        return target;
    }

    7,输出结果

    function test(n, o) {
        console.log(o);
        return {
            test: function (m) {
                return test(m, n);
            }
        };
    }
     
    var a = test(0);
    a.test(1);
    a.test(2);
    var b = test(0).test(1).test(2).test(3);
    var c = test(0).test(1);
    c.test(2);
    c.test(3);

    输出参考:

    undefined
    0
    0
    undefined
    0
    1
    2
    undefined
    0
    1
    1

    8.async/await的了解

    async函数返回的是一个promise对象,如果async函数中有return语句,那么promise对象resolve拿到的数据就是这个return后的数据。如果没有,那么就是undefined。async函数的内部是同步的方式执行的。

    9.构造函数的理解

    function Person(name){
        this.name = name;
        return name;
    }
    let p1 = new Person('Tom');
    function Person(name){
        this.name = name;
        return {};
    }
    let p2 = new Person('Tom');

    p1为{name:‘Tom’},而p2为{}。

    解释:构造函数不需要显示的返回值。使用new来创建对象(调用构造函数)时,如果return的是非对象(数字、字符串、布尔类型等)会忽略返回值,返回的是this;如果return的是对象,则返回该对象(注:若return null也会忽略返回值)。

     

    10.函数的防抖与节流的简单代码实现

     

  • 相关阅读:
    POJ 3258 二分答案
    Prototype 模式示例代码 (C++)
    offsetof 和 container_of
    二进制整数中的“1”
    Binary Tree Traversal Algorithms (二叉树遍历算法)
    A* Pathfinding Algorithm
    Axis­ Aligned 
Rectangles (Google 面试题, 2016网易游戏校招笔试)
    [LeetCode] Burst Ballons
    C++ 继承语义下构造函数中的对象指针
    kill-9和kill-15的区别
  • 原文地址:https://www.cnblogs.com/937522zy/p/13427985.html
Copyright © 2020-2023  润新知