摘要:index.js function Animal(race) { this.race = race; } Animal.prototype.eat = function () { console.log(`${this.race} is eatting.`); }; const bird = new
阅读全文
摘要:index.js const list = [1, , 3]; Array.apply(null, list); // [1, undefined, 3] [...list]; // [1, undefined, 3]
阅读全文
摘要:index.js const arrayLikeObj = { 0: 1, length: 2 }; [].slice.apply(arrayLikeObj); // [1, empty] Array.prototype.slice.apply(arrayLikeObj); // [1, empty
阅读全文
摘要:index.js requestIdleCallback(myNonEssentialWork); function myNonEssentialWork(deadline) { while (deadline.timeRemaining() > 0) { doWorkIfNeeded(); } }
阅读全文
摘要:index.js function Foo() {} const foo = new Foo(); console.log(foo instanceof Foo); // true // 等价于 console.log(Foo.prototype.isPrototypeOf(foo)); // tr
阅读全文
摘要:Boolean null, undefined, false, NaN, '', +0, -0, 0n --> false,其它均为 true Number 能转则转,不能则 NaN(undefined),特例 Symbol 会报错。 String "true", "0", "1,2", "[obj
阅读全文
摘要:index.js const instance = {}; console.log(instance.__proto__ Object.prototype); // true, 浏览器才需要部署 console.log(instance.constructor.prototype Object.pr
阅读全文
摘要:index.js window.screenX window.screenY
阅读全文
摘要:index.js function Person() {} Person.prototype.sayHello = function () {}; console.log(Object.getPrototypeOf(new Person())); // {sayHello: ƒ, construct
阅读全文
摘要:index.js // 构造函数和一般函数没有区别,都可以通过 name 属性获取函数名 function Person() {} const lilei = new Person(); console.log(lilei.constructor.name); // 'Person' console
阅读全文
摘要:index.js function Person() { this.race = "human being"; // 实例属性 } Person.prototype.color = "yellow"; // 公共属性/原型属性 const instance = new Person(); insta
阅读全文
摘要:index.js const instance = { name: "lilei", age: 13, }; Object.defineProperty(instance, "gender", { value: 1, enumerable: false, }); Object.getOwnPrope
阅读全文
摘要:index.js const objProto = {}.__proto__ || Object.getPrototypeOf({}) || Object.prototype; console.log(Object.getPrototypeOf(objProto) || objProto.__pro
阅读全文
摘要:有三种方法: 1. Function.prototype.call(); 2. Function.prototype.apply(); 3. Function.prototype.bind(); 一、Function.prototype.call() 可以指定函数在参数对象环境下执行; var ob
阅读全文
摘要:有三种方法: 1. Function.prototype.call(); 2. Function.prototype.apply(); 3. Function.prototype.bind(); 一、Function.prototype.call() 可以指定函数在参数对象环境下执行; var ob
阅读全文
摘要:index.js const obj = { foo() { console.log(this); // obj const self = this; const bar = (function () { console.log(self); // obj })(); }, }; obj.foo()
阅读全文
摘要:index.js // 方法1:严格模式 function Person(name) { "use strict"; this.name = name; } const lilei = Person("李雷"); // Error console.log(lilei.name); index.js
阅读全文
摘要:index.js const foo = Object(null); const bar = Object.create(null); console.log(foo instanceof Object); // true console.log(bar instanceof Object); //
阅读全文
摘要:index.js const specialObj = Object.create(null); console.log(specialObj.__proto__); // undefined
阅读全文
摘要:index.js function Foo() { const list = []; this.push = function (val) { list.push(val); }; this.getList = function () { console.log(list); }; } const
阅读全文