领英前端店面

第一问:

  • Event bubbling
  • Prototype vs. class
  • Accessibility
  • Callback vs. promise

第二问:

let Foo = function(a) {
    this.a = a;
    this.bar = function() {
        return this.a;
    }
    this.baz = function() {
        return this.a;
    };
};

Foo.prototype = {
    biz: function() {
        return this.a;
    }
};

let f = new Foo(7);
// what will be the output?
f.bar();
f.baz();
f.biz();

Follow-up:

How to make the first and third also return 7?

第三问

// Implement Fibonacci

function memoize(fn) {
    // todo
}

function fib(n) {
    // fibonacci
    return n;
}

fib(n);

let memoizedFib = memoize(fib);
memoizedFib(n);

第四问

// Implement Infinite Scroll

/**
 * API Docs
 * ---------
 * /posts?page=0 => [{id: 1, title: "Post 1"}, {id: 2, title: "Post 2"}, {id: 3, title: "Post 3"}, N...]
 * /posts?page=1 => [{id: 4, title: "Post 4"}, {id: 5, title: "Post 5"}, {id: 6, title: "Post 6"}, N...]
 * /posts?page=N => [N...]
 */

// HTML
// ---------
<ul id="posts"></ul>

// JS
// ---------
$(window).on("scroll", scrollHandler);


function scrollHandler() {
  // todo
}