This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 栈实现 */ | |
const Stack = (() => { | |
// 闭包使得item为私有变量,避免外部调用(ES6无私有变量) | |
let item = new WeakMap(); | |
// 模拟实现栈 Stack | |
class Stack { | |
constructor() { | |
item.set(this, []); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict" | |
/**事件式编程 */ | |
class EventEmiter { | |
constructor(debug) { | |
this._debuger_ = !!debug; | |
this._callback_ = {}; | |
this.commonApi(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*-------------------------------------------------------------- | |
* Copyright (c) Nickbing Lao<[email protected]>. All rights reserved. | |
* Licensed under the MIT License. | |
*-------------------------------------------------------------*/ | |
const fs = require("fs"); | |
const path = require("path"); | |
const reg = /(main|styles|scripts|polyfills|inline).[0-9a-z]*.bundle.(css|js)/g; | |
let indexPagePath = path.join(__dirname, './dist/index.html'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// download & parse | |
if ('serviceWorker' in navigator) { | |
navigator.serviceWorker.register('./sw.js?' + new Date().getTime()).then(function(registration) { | |
// 注册成功 | |
console.log('ServiceWorker registration successful with scope:' + registration.scope); | |
}).catch(function(err) { | |
// 注册失败1 | |
console.log('ServiceWorker registration failed:', err); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 下载统一接口,判断浏览器是否支持a标签download属性,如果不支持采用form表单提交方式下载文件 | |
* @param url | |
* @param fileName | |
*/ | |
export function download(url: string, fileName?: string) { | |
const isSupportDownload = 'download' in document.createElement('a'); | |
if (isSupportDownload) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var identityCodeValid = function (code) { | |
var city = { | |
11: "北京", | |
12: "天津", | |
13: "河北", | |
14: "山西", | |
15: "内蒙古", | |
21: "辽宁", | |
22: "吉林", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 获取对象obj的属性key的值,属性key支持多层,如 a.b.c | |
* | |
* @sample | |
* var obj = { a: { b: { c: 1 } } } | |
* var result = getProperty(c,'a.b.c'); | |
* // 结果为 1 | |
* | |
* @param obj 目标对象 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 类的封装和信息的隐藏 | |
* | |
* 本例子使用闭包来实现静态变量熟悉和方法,通过创建一个受保护的变量空间,可以实现公用、私用和特权成员,以及 | |
* 静态成员和常量。 | |
* | |
* 概念: | |
* 1、特权方法(privileged method) 指有权访问私有变量和私有函数的公有方法 | |
* 2、非特权方法(non-privileged method) 指无需(或没有权限)访问私有变量和私有函数的公有方法 | |
* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var currying = function(fn) { | |
var _weight = 0; | |
var _args = []; | |
return function() { | |
if (!arguments.length) { | |
return fn.apply(this, _args); | |
} else { | |
Array.prototype.push.apply(_args, arguments); | |
return arguments.callee; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var geoCoordMap = { | |
'广州': [113.5107,23.2196], | |
'北京': [116.4551,40.2539], | |
'天津': [117.4219,39.4189], | |
'上海': [121.4648,31.2891], | |
'重庆': [106.557165,29.563206], | |
'河北': [114.508958,38.066606], | |
'河南': [113.673367,34.748062], | |
'云南': [102.721896,25.047632], | |
'辽宁': [123.445621,41.806698], |