Giter VIP home page Giter VIP logo

javascript-test's People

Watchers

 avatar

javascript-test's Issues

promise

Promise.resolve(1)
  .then(2)
  .then(Promise.resolve(3))
  .then(console.log)

js事件循环相关题目

setTimeout(function () {
  new Promise(function (res) {
    res()
    console.log(1);
  }).then(function () {
    console.log(2);
  })
  setTimeout(function () {
    console.log(3);
  }, 0)
  console.log(4);
}, 0)

setTimeout(function () {
  console.log(5);
}, 0)

new Promise(function (res) {
  console.log(6);
  res()
}).then(function () {
  console.log(7);
})

function fn1() {
  return new Promise(function (res) {
    console.log(8);
    res()
  })
}

fn1().then(function () {
  console.log(9);
})

console.log(10);

变量查找

function fun(n, o) {
    console.log(o)
    return {
      fun: function (m) {
        return fun(m, n)
      }
    }
}
测一:
var a = fun(0)
a.fun(1)
a.fun(2)
a.fun(3)
测二:
var b = fun(0).fun(1).fun(2).fun(3)
测三:
var c = fun(0).fun(1)
c.fun(2)
c.fun(3)

typeof

console.log(typeof null)
console.log(typeof undefined)
console.log(typeof NaN)
console.log(typeof [])
console.log(typeof {})
console.log(typeof Symbol())
console.log(typeof /a/)
console.log(typeof Object('1'))
console.log(typeof Object(true))

console.log(typeof new Array([1, 2, 3]))
console.log(typeof new String('1'))
console.log(typeof new Function())
console.log(typeof class c {})

function fn() {}
console.log(typeof fn)

原型

function A() {}
function B(a) {
    this.a = a;
}
function C(a) {
    if (a) {
        this.a = a;
    }
}
A.prototype.a = 1;
B.prototype.a = 1;
C.prototype.a = 1;

console.log(new A().a); 
console.log(new B().a);
console.log(new C(2).a);

this的指向

var name = 'window'
function Person (name) {
  this.name = name
  this.foo1 = function () {
    console.log(this.name)
    return function () {
      console.log(this.name)
    }
  }
  this.foo2 = function () {
    console.log(this.name)
    return () => {
      console.log(this.name)
    }
  }
  this.foo3 = () => {
    console.log(this.name)
    return function () {
      console.log(this.name)
    }
  }
  this.foo4 = () => {
    console.log(this.name)
    return () => {
      console.log(this.name)
    }
  }
}
var person1 = new Person('person1')
person1.foo1()()
person1.foo2()()
person1.foo3()()
person1.foo4()()

instanceof 类题目

var A = function() {}
A.prototype = {first:'first'}
var a = new A()
A.prototype = {second:"second"} 
var b = new A()
console.log(a instanceof A)
console.log(b instanceof A)
console.log(A.prototype)
console.log(a.__proto__)
console.log(b.__proto__)

原型相关题目

Function.prototype.a = () => {
  console.log(1);
}
Object.prototype.b = () => {
  console.log(2);
}
function A() {}
const a = new A();

a.a();
a.b();
A.a();
A.b();

优先级

// 例1:
let num1 = 1
if(num1-- > 0){ 
 console.log(1)
}
// 例2:
let num2 = 1
if(--num2 > 0){
  console.log(2)
}

new 结果的考察

function A() { return 1 };
function B() { return true };
function C() { return { abc: 123 } };
function D() { return null };
function E() { return undefined };

console.log(new A());
console.log(new B());
console.log(new C());
console.log(new D());
console.log(new E());

变量提升

// 例1:
console.log(a);
var a = 10;
console.log(a);

valueOf和toString

  const data = {
    valueOf: () => 123,
    toString: () => 'abc'
  }
  
  console.log(data == 123);
  console.log(data === 123);
  console.log(`${data}` === 'abc');
  console.log(data + '' === 'abc');

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.