This file contains 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
function getThirdResoure() { | |
var resp = null; | |
var tags = document.querySelectorAll('iframe[src],frame[src],script[src],link[rel=stylesheet],object[data],embed[src]'); | |
for(var i = 0; i < tags.length; i++){ | |
var tag = tags[i]; | |
var a = document.createElement('a'); | |
a.href = tag.src||tag.href||tag.data; | |
if(a.hostname != location.hostname){ | |
resp = resp || []; | |
resp.push({name: tag.localName, href: a.href}); |
This file contains 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
let CHARS = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789-_.~!*()'; // except \' | |
function decToRadixN(radixChars, numLen) { | |
let result = []; | |
let radix = radixChars.length; | |
return function cacl(dec) { | |
result.unshift(dec % radix); | |
if (dec >= radix) { | |
dec = Math.floor(dec / radix); | |
return cacl(dec, radix); | |
} |
This file contains 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
// 返回字符串的实际长度, 一个汉字算2个长度 | |
String.prototype.strlen = function () { | |
return this.replace(/[^\x00-\xff]/g, "**").length; | |
} |
This file contains 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
// ~符号用在JavaScript中有按位取反的作用,~~即是取反两次,而位运算的操作值要求是整数,其结果也是整数,所以经过位运算的都会自动变成整数,可以巧妙的去掉小数部分,类似于parseInt,比如: | |
let a = 1.23; | |
let b = -1.23; | |
console.log(~~a); // 1 | |
console.log(~~b); // -1 |
This file contains 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
Function.prototype.before = function(beforefn){ | |
var _self = this; //保存原函数的引用 | |
return function() { //返回包含了原函数和新函数的 ‘代理’函数 | |
beforefn.apply(this, arguments); //执行新函数,修正this,新函数在原函数之前执行 | |
return _self.apply(this, arguments); //执行原函数,并保证this不会被劫持 | |
} | |
} | |
Function.prototype.after = function(afterfn) { | |
var _self = this; |
This file contains 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
// reduce方法 | |
let arr = [1, 2, 3, 4, 5, 6]; | |
let reduceResult = arr.reduce((x, y) => { | |
return x + y | |
}, 123); | |
console.log(reduceResult); |
This file contains 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
Array.prototype.unique = function() { //查找索引 indexOf | |
var ret = [] | |
for (var i = 0; i < this.length; i++) { | |
if (ret.indexOf(this[i]) == -1) { | |
ret.push(this[i]) | |
} | |
} | |
return ret; | |
} | |
Array.prototype.unique = function() { //借用对象 |
This file contains 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 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); |
This file contains 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 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": |
This file contains 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
function chainable(fn) { | |
console.info('a', this);//window | |
return function () { | |
console.info('b1', this); | |
fn.apply(this, arguments); | |
console.info('b2', this); | |
return this; | |
}; | |
} |