Skip to content

Instantly share code, notes, and snippets.

View MrKou47's full-sized avatar

Kbscript MrKou47

View GitHub Profile
@MrKou47
MrKou47 / singleton_pattern.js
Last active July 28, 2017 03:57
单例模式
/**
* 单例模式
* 避免重复创建相同对象
* example:
* let a = new TestClass();
* let b = new TestClass();
* a === b // false
* 如何a===b 为 true
*/
@MrKou47
MrKou47 / new_ identifier.js
Created July 28, 2017 04:24
关于js new 标识符的一些点
function Car() {
console.log(this);
console.log(this instanceof Car);
this.a = 'i am a ';
}
var t = new Car();
var tt = Car();
console.log(t);
@MrKou47
MrKou47 / factory_pattern.js
Created July 28, 2017 04:57
工厂模式
let carFactory = (function (name) {
function Benz() {
this.name = 'benz';
}
function BMW() {
this.name = 'bmw';
}
return function(name) {
switch (name) {
case 'benz':
@MrKou47
MrKou47 / pub_sub.js
Last active November 27, 2017 02:40
发布/订阅模式
function PubSub() {
this.eventList = [];
}
PubSub.prototype.subscrible = function (eventName, callback) {
const currentEvent = this.eventList.find(obj => obj && obj.name === eventName);
if (currentEvent) {
this.eventList.find(obj => obj && obj.name === eventName).callback = callback;
} else {
this.eventList.push({ name: eventName, callback, });
@MrKou47
MrKou47 / minify-json.js
Last active November 25, 2017 08:15
some code for minilize json file
/**
* 步骤
* 1. 先读取文件夹 再 读取所有的json文件
* 2. 再依次读取json内容
* 3. 替换文件中的内容
* 4. 写新的文件 到dist文件夹
*/
function minifyJson(rootPath) {
const saveDirName = 'dist';
const baseFolderName = path.basename(rootPath);
@MrKou47
MrKou47 / tslint.json
Last active December 5, 2017 03:47
typescript basic lint config
{
"rules": {
"no-unused-expression": true,
"no-duplicate-variable": true,
"no-unused-variable": true,
"curly": false,
"class-name": true,
"semicolon": [true,"always"],
"triple-equals": true,
"no-var-requires": false,
@MrKou47
MrKou47 / dunk.md
Last active June 30, 2020 19:00
Training Plan

Dunking

Training Plan:

Day 1:

  • Squats (3 Sets of 5 Reps)
  • Lunges (3 Sets of 10 Reps)
  • Frog Jumps (5 Sets of 10 Reps)
  • Box Jumps (3 Sets of 10 Reps)
@MrKou47
MrKou47 / 0.bundle.js
Last active March 30, 2018 09:13
dynamic import 测试
webpackJsonp([0],[
/* 0 */,
/* 1 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
const a = 2;
/* harmony default export */ __webpack_exports__["default"] = (a);
function run() {
@MrKou47
MrKou47 / 0.dynamic_bundle.js
Last active April 3, 2018 05:31
dynamic以及css-loader,style-loader打包代码分析
webpackJsonp([0],{
/***/ 9:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
@MrKou47
MrKou47 / css-loader-with-optionPlugin.js
Last active June 28, 2018 08:57
css-loader-with-optionPlugin example
if (process.env.NODE_ENV === undefined) {
process.env.NODE_ENV = 'development';
}
const webpack = require('webpack');
const brfs = require('brfs');
const autoprefixer = require('autoprefixer');
const libraryName = process.env.NODE_ENV === 'development' ? '[name]' : '[name]_[chunkhash]';
const styleLoaderName = 'style-loader';