Javascript收集面试题库干货

出套 前端 笔试题 坑自己

2018-12-26  本文已影响5人  空无一码

作为一个前端老司机,近两年更多的是出笔试题 考别人,突然想给 自己出一套 笔试题 坑自己,同时 也以此 分享给 需要的人。

HTML 部分

CSS 部分

JS 部分

Function.prototype.bind2 = function (context) {
    if (typeof this !== "function") {
      throw new Error("Function.prototype.bind - what is trying to be bound is not callable");
    }
    var self = this;
    var args = Array.prototype.slice.call(arguments, 1);
    var fNOP = function () {};
    var fbound = function () {
        self.apply(this instanceof self ? this : context, args.concat(Array.prototype.slice.call(arguments)));
    }
    fNOP.prototype = this.prototype;
    fbound.prototype = new fNOP();
    return fbound;
}
// https://blog.csdn.net/daimomo000/article/details/72897035
var x = 1; 
function test() {
   var x = 2;
   return () => {
     x += 1;
   }
}

var t = test();
t();
console.log(x); // 1 闭包形成局部变量
var x = 1;
if(!(y in window)) {
  var y = 2;
  x += 1;
} else {
  x += 2;
}
console.log(x); // 3
console.log(y); // undefined
function Foo() {
  getName = function() {
    console.log(1)
  }
  return this;
}

Foo.getName = function() {console.log(2)}
Foo.prototype.getName = function() {console.log(3)}
var getName = function() {console.log(4)}
function getName() {console.log(5)}

Foo.getName(); // 2
getName(); // 4
Foo().getName(); // 1
console.log('dd', getName)
getName(); // 1

new Foo.getName(); // 2
new Foo().getName(); // 3
new new Foo().getName(); // 3

浏览器 部分

主流框架使用

vue父子组件间传值: 父组件通过标签上面定义传值, 子组件通过props方法接受数据;子组件通过$emit方法传递参数向父组件传递数据。

Vue生命周期钩子函数:

算法

let unique =  function(arr){
  let hash={};
  let data=[];
  for (let i=0;i < arr.length; i++){
    if (!hash[arr[i]])  {
      hash[arr[i]] = true;
      data.push(arr[i]);
    }      
  }
  return data
}
function ListNode(val) {
   this.val = val;
   this.next = null;
}
// 方法1
var mergeTwoLists = function(l1, l2) {
    var head=new ListNode(0);
    var curr=head;
    var p=l1,q=l2;
    while(p!=null&&q!=null){
        if(p.val<q.val){
            curr.next=new ListNode(p.val)
            curr=curr.next;
            p=p.next;
        }else if(p.val==q.val){
            curr.next=new ListNode(p.val);
            curr=curr.next;
            curr.next=new ListNode(p.val);
            curr=curr.next
            p=p.next;
            q=q.next;
        }else{
            curr.next=new ListNode(q.val);
            curr=curr.next;
            q=q.next;
        }
    }
    if(p!==null){
        curr.next=p;
    }
    if(q!==null){
        curr.next=q;
    }
    return head.next; 
};

// 方法2 将l2合并到l1
// 外层循环控制遍历第二条链表,内层循环负责插入新节点,所以是O(m*n)的算法。
var mergeTwoLists = function(l1, l2) {
    while(l2){
        var prev = null;
        var cur = l1;
        while(cur && l2.val > cur.val){
            prev = cur;
            cur = cur.next;
        }
        var newNode = new ListNode(l2.val);
        newNode.next = cur;
        if(prev){
            prev.next = newNode;
        }else{
            l1 = newNode;
        }
        l2 = l2.next;
    }
    return l1;
};
上一篇 下一篇

猜你喜欢

热点阅读