- 输出
function Foo() {
getName = function() {alert(1)};
return this;
}
Foo.getName = function() {alert(2)};
Foo.prototype.getName = function() {alert(3)};
var getName = function() {alert(4)};
function getName() {alert(5)};
// output
Foo.getName();
getName();
Foo().getName();
getName();
new Foo.getName();
new Foo().getName();
new new Foo().getName();
- 写出函数test()
/**
* @function poll, randomly returns a boolean value
* @return {Boolean}
*/
function poll() {...}
/**
* @function test, 每隔n秒执行一次poll,若poll返回值为true, 则执行callback,否则在
* n = 1.5 * n 秒后再次执行直到poll返回true, n 初始值为1
* @param {function} poll
* @param {function} callback
*/
function test(poll, cb) {...}
- 写出函数add()
add(1)(2) // 3
add(1,2) // 3
- 输出
setTimeout(function () {
console.log(1);
}, 0);
new Promise(function executor(resolve) {
console.log(2);
for (var i = 0; i < 10000; i++) {
i == 9999 && resolve();
}
console.log(3);
}).then(function () {
console.log(4);
});
console.log(5);
- 写出.clearfix类,用于清除浮动
- 使用flex布局实现
screen width > 768px
┌───────────────────────┐
│ ┌────┐ ┌────┐ ┌────┐ │
│ │ a │ │ b │ │ c │ │
│ └────┘ └────┘ └────┘ │
└───────────────────────┘
screen width <= 768px
┌───────────────────────┐
│ ┌──────────────────┐ │
│ │ b │ │
│ └──────────────────┘ │
│ ┌───────┐ ┌───────┐ │
│ │ a │ │ c │ │
│ └───────┘ └───────┘ │
└───────────────────────┘