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
| /** | |
| * @param {String} substr 用来搜索的子串 | |
| * @param {String} str 被搜索的字符串 | |
| * @return {Array} 由匹配到的索引组成的数组 | |
| */ | |
| function getIndexes(substr, str) { | |
| var arr = []; | |
| var index; | |
| var len = 0; | |
| var slicedStr = str; |
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
| // JS 浮点数四则运算精度丢失解决方案 | |
| // 计算小数点后面有几位 | |
| function getBits(num) { | |
| var eq1; | |
| return (eq1 = num.toString().split('.')[1]) ? eq1.length : 0; | |
| } | |
| // 加法 | |
| Number.prototype.add = function(arg) { |
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
| /** | |
| * @param {String} downloadUri | |
| * @param {Boolean} useIFrame | |
| */ | |
| function startDownloading(downloadUri, useIFrame) { | |
| if (!downloadUri || !downloadUri.length) { | |
| return; | |
| } | |
| if (useIFrame === void 0) { |
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
| // example 1 | |
| function a(c) { | |
| // 在a的作用域中声明b | |
| return function b(d) { | |
| // b中使用了a的局部变量c | |
| c += 1; | |
| return c + d; | |
| } | |
| } |
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
| /** | |
| * @param {Function} subType | |
| * @param {Function} superType | |
| */ | |
| function inheritPrototype(subType, superType) { | |
| // 以一个空函数作为中介,保证不把父类构造器中的属性带进原型链 | |
| function F() {} | |
| // 把F的prototype指向父类的prototype,修改整个prototype而不是部分prototype | |
| F.prototype = superType.prototype; | |
| // new F()完成两件事情,1. 执行F构造函数,为空;2. 执行F的prototype的内存分配,这里就是父类,也就是Person的getAge方法 |
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
| // @param {Boolean} defaults 默认不传参,为undefined,目标对象的已有属性不被覆盖;为true,则可以被覆盖 | |
| function createAssigner(defaults) { | |
| function extend(obj) { | |
| for (var i = 1; i < arguments.length; i++) { | |
| var def = arguments[i]; | |
| for (var key in def) { | |
| if (!defaults || obj[key] === void 0) { | |
| obj[key] = def[key]; | |
| } |
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
| html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video { | |
| margin: 0; | |
| padding: 0; | |
| border: 0; | |
| font-size: 100%; | |
| font: inherit; | |
| vertical-align: baseline | |
| } | |
| article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section { |
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
| /* Based on Alex Arnell's inheritance implementation. */ | |
| /** section: Language | |
| * class Class | |
| * | |
| * Manages Prototype's class-based OOP system. | |
| * | |
| * Refer to Prototype's web site for a [tutorial on classes and | |
| * inheritance](http://prototypejs.org/learn/class-inheritance). | |
| **/ |
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
| // 先求两个的对称差,用求得的结果与其后的数组重复之前步骤 | |
| function sym() { | |
| var ans = []; | |
| var args = Array.prototype.slice.call(arguments); | |
| var len = args.length; | |
| var two; | |
| function uniq(arr) { | |
| var output = []; | |
| var objMark = {}; | |
| arr.forEach(function(item, index) { |