Skip to content

Instantly share code, notes, and snippets.

@naixy28
Created September 26, 2017 06:12
Show Gist options
  • Select an option

  • Save naixy28/44918de42c087ab49eeeae6ac52fd98d to your computer and use it in GitHub Desktop.

Select an option

Save naixy28/44918de42c087ab49eeeae6ac52fd98d to your computer and use it in GitHub Desktop.
int-simple

js

  1. 输出
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();
  1. 写出函数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) {...}    
  1. 写出函数add()
    add(1)(2) // 3
    add(1,2)  // 3
  1. 输出
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);

CSS

  1. 写出.clearfix类,用于清除浮动
  2. 使用flex布局实现
screen width > 768px
┌───────────────────────┐
│ ┌────┐ ┌────┐ ┌────┐  │
│ │ a  │ │ b  │ │ c  │  │
│ └────┘ └────┘ └────┘  │
└───────────────────────┘

screen width <= 768px 
┌───────────────────────┐
│ ┌──────────────────┐  │
│ │        b         │  │
│ └──────────────────┘  │
│ ┌───────┐  ┌───────┐  │
│ │ a     │  │ c     │  │
│ └───────┘  └───────┘  │
└───────────────────────┘
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment