JavaScript总结
allan5945
杂而不乱
展开
-
js的函数自执行
// js的函数自执行// 常见的写法(function () { console.log('hello');})();除此之外,还有const f = function () { console.log('hello');}();~function () { console.log('hello');}();!function () { console.log('hello');}();+function () { console.log('.原创 2021-04-16 11:03:19 · 132 阅读 · 0 评论 -
js的几个小技巧
1、解构原始数据 const rawUser = { name: 'Allan', age: '25', sex: "man" }; let user = {}; ({ name: user.name, age: user.age} = rawUser); console.log(user); // {name: "Al...原创 2020-04-26 14:05:26 · 154 阅读 · 0 评论 -
useState回调函数
在看的小朋友,新的react hook写法,官方默认setState方法移除了回调函数,推荐使用useEffect,但是改动的数据过多还是有很多问题。so,我在useState基础上扩展了回调函数功能,就可以像以前类写法一样传递回调方法啦。话不多说上代码import {useEffect, useState} from "react";function useCallbackStat...原创 2020-04-20 14:21:42 · 20600 阅读 · 0 评论 -
DllPlugin极大优化打包速度
话不多说直接上代码/步骤1、安装webpack4.x2、创建 webpack.dll.config.js 的文件3、这样写入配置const path = require('path');const DllPlugin = require('webpack/lib/DllPlugin');const rootPath = require('app-root-path')...原创 2020-04-01 14:51:05 · 435 阅读 · 0 评论 -
js中的bind的使用
"use strict" var c = { b:"66" }; var a = function () { console.log(this.b) }.bind(c); a(); // 输出66 此时a的指向就指向到了c原创 2018-10-09 14:11:53 · 111 阅读 · 0 评论 -
js中 改变this指向 之 call apply
"use strict" var a = function (c) { console.log(this,c) }; var c = { b:"66" }; a(); //undefined,undefined a.apply(c,[999]); // c,999 a.call(c,999); /...原创 2018-10-09 14:05:33 · 89 阅读 · 0 评论 -
js中的this指向
"use strict" var obs = { a:1, al:function () { console.log(this) } }; var A = function () { console.log(this) }; var c = obs.al;...原创 2018-10-09 13:53:12 · 76 阅读 · 0 评论 -
js中的原型链
var A = function () {}; A.prototype.sex = "man"; var B = function () { this.name = "allan"; this.age = 22; }; var a = new A(); B.prototype = a; console.log...原创 2018-10-08 20:47:12 · 103 阅读 · 0 评论 -
Object.create 的浅拷贝
var A = function () { this.name = "allan"; this.age = 23; }; var d = new A(); var c = Object.create(d); d.age = 24; console.log(c.age,d.age); // 输出24,24 /...原创 2018-10-08 20:23:51 · 3056 阅读 · 0 评论 -
js的数据封装
var B = function () { var _name = "allan"; return { getName:function () { return _name; } } }; console.log(new B().getName()...原创 2018-10-08 20:05:47 · 577 阅读 · 0 评论 -
js对象的多态性
var A = function () {}; var B = function () {}; A.prototype.sound = function () { console.log("A"); }; B.prototype.sound = function () { console.log("B"); };...原创 2018-10-08 19:57:42 · 248 阅读 · 0 评论 -
instanceof判断构造函数
var A = function () {}; var B = function () {}; console.log(new A() instanceof A); // true 构造函数是A console.log(new B() instanceof A); // false 构造函数不是A使用 instanceof 来判断实例的构造函数。...原创 2018-10-08 19:50:35 · 622 阅读 · 0 评论