View class-weakmap.js
const privateProps = new WeakMap();
function _convertToLowercase(val) {
return val.toLowerCase();
}
class Person {
constructor(name) {
privateProps.set(this, {name: name});
}
getName() {
return _convertToLowercase(privateProps.get(this).name);
View cmp.js
//老记混顺序,特此整理一下
function cmp(a, b){
//a 在前-1,a 在后1
if(a<b) return 1; //a小于b的情况下,a在后
if(a>b) return -1;//a大于b的情况下,a在前
return 0;
}
var a=[1,10,5,9,2];
console.log(a.sort(cmp));
View compareVerison.js
var versions= [{"version":"1.3.0-beta.2"},{"version":"1.3.0-beta.19"},{"version":"1.3.0-beta.18"},{"version":"1.3.0-beta.17"},{"version":"1.3.0-beta.16"},{"version":"1.3.0-beta.15"},{"version":"1.3.0-beta.14"},{"version":"1.3.0-beta.13"},{"version":"1.3.0-beta.12"},{"version":"1.3.0-beta.11"},{"version":"1.3.0-beta.10"},{"version":"1.3.0-beta.1"},{"version":"1.3.0"},{"version":"1.2.9"},{"version":"1.2.8"},{"version":"1.2.7"},{"version":"1.2.6"},{"version":"1.2.5"},{"version":"1.2.4"},{"version":"1.2.30"},{"version":"1.2.3"},{"version":"1.2.29"},{"version":"1.2.28"},{"version":"1.2.27"},{"version":"1.2.26"},{"version":"1.2.25"},{"version":"1.2.24"},{"version":"1.2.23"},{"version":"1.2.22"},{"version":"1.2.21"},{"version":"1.2.20"},{"version":"1.2.2"},{"version":"1.2.19"},{"version":"1.2.18"},{"version":"1.2.17"},{"version":"1.2.16"},{"version":"1.2.15"},{"version":"1.2.14"},{"version":"1.2.13"},{"version":"1.2.12"},{"version":"1.2.11"},{"version":"1.2.10"},{"version":"1.2.1"},{"version":"1.2.0rc3"},{"version":
View chainable.js
function chainable(fn) {
console.info('a', this);//window
return function () {
console.info('b1', this);
fn.apply(this, arguments);
console.info('b2', this);
return this;
};
}
View doubleBitwise.js
Math.floor(4.9) === 4 //true
~~4.9 === 4 //true
(4.9 | 0) === 4 //true
View shortFunctionCall.js
function x() {
console.log('x')
};
function y() {
console.log('y')
};
var z = 3;
(z==3?x:y)();
View declareAndCall.js
var func = (function f(a) {
console.log(a);
return f;
})('Hello World');
View Analytics.js
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function() {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
View debounce&throttle.js
$.debounce = function(fn, time, ctx) {
var ret = 0;
if( typeof time !== 'number' ) {
ctx = time;
time = 50;
}
time = time || 50;
return function() {
var args = [].slice.apply(arguments);
// 注意是ctx的问题
View shareFunc.js
function shareFunc(func){
//初始化函数运行过程中依赖的变量
//之前一般的方式是声明全局变量,程序的阅读与理解难度增加,全局变量容易受干扰
var varWraper ={
a:0
}
return function(){
var args = [].slice.apply(arguments);
args.push(varWraper);
var ret = func.apply(this,args);