The Hottest Porn Videos Online mecum.porn Quality porns videos Free indian porn tube videos indiansexmovies.mobi hot indian women watch online

Tag: snippets

4 Posts

JS Tips
任何变量,如果未经声明就赋值,此变量是属于 window 的属性,而且不会做变量提升。(注意,无论在哪个作用域内赋值) function foo() { var a = (b = 100); // a和b的区别 } defer and async The best thing to do to speed up your page loading when using scripts is to put them in the head, and add a defer attribute to your script tag. Efficiently load JavaScript with defer and async
JS 数组
Fundamental ECMAScript中new Array(len)的操作 判断 len 是否为合法数字(小于 2^32 - 1 的正整数),如果不是则抛出错误; 创建一个 JavaScript Array 实例; 将这个实例对象的 length 属性设置为入参的值; 但该数组此时并没有包含任何实际的元素,而且不能理所当然地认为它包含 len 个值为 undefined 的元素 More empty和undefined的区别 导致数组的map、some、filter、includes、for in、for of、findIndex、sort等方法的差异 稀疏数组、密集数组的互相转换 V8 访问对象有两种模式:字典模式 和 快速模式 JavaScript 之稀疏数组与密集数组 稀疏数组与密集数组 伪数组(ArrayLike) 按索引方式储存数据 length不会动态变化 伪数组的原型链中没有 Array.prototype,因此不具有push、forEach等方法 常见的如arguments、DOM children 元素集。 // 伪数组转真数组 Array.prototype.slice.call(ArrayLike); [].slice.call(ArrayLike); Array.from(ArrayLike); sort方法 默认按 Unicode 编码排序 自定义排序规则:return 大于 0 的值——元素交换位置,return 小于 0 的值——元素位置不变,return 等于 0 的值——不交换位置 // 冒泡排序 arr.sort((a, b) => a - b); forEach会改变原数组吗,map()会吗 :question: arr.reduce(function (previousValue, currentValue, currentIndex, arr) {}, initialValue); e.g. 统计元素出现的次数、找最大值等 清空数组 array.splice(0); //方式1:删除数组中所有项目 array.length = 0; //方式2:length属性可以赋值,在其它语言中length是只读 array = []; //方式3:推荐 join的应用 相比字符串拼接 由于字符串的不变性,str 拼接过多的话,性能差,且容易导致内存溢出(很多个 str 都堆放在栈里)
JS 日期格式化
JS日期格式化转换方法 Date.prototype.format = function(fmt) { var o = { "M+" : this.getMonth()+1, //月份 "d+" : this.getDate(), //日 "h+" : this.getHours(), //小时 "m+" : this.getMinutes(), //分 "s+" : this.getSeconds(), //秒 "q+" : Math.floor((this.getMonth()+3)/3), //季度 "S" : this.getMilliseconds() //毫秒 }; if(/(y+)/.test(fmt)) { fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); } for(var k in o) { if(new RegExp("("+ k +")").test(fmt)){ fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length))); } } return fmt; } 龙恩0707 JS日期格式化转换方法 References Moment.js 轻量级的JavaScript时间库
JS Function
函数声明的方式 function关键字 函数表达式(匿名函数)var 变量名 = function([形参1,形参2...形参N]){} 构造函数var 变量名/函数名 = new Function('形参1', '形参2', '函数体'); 函数调用 func() func.call() (function(){})(); new func() 事件调用 定时调用 函数类数组实参arguments 函数调用隐含传入上下文对象this和封装实参的对象arguments 在递归调用中用arguments.callee代替自身函数名可以接触函数体内代码与函数名的耦合,但会导致函数体内的this对象被更改,同时访问arguments是个很昂贵的操作,因为它是个很大的对象,每次递归调用时都需要重新创建,影响现代浏览器的性能,还会影响闭包。 函数预编译 函数预编译,发生在函数执行的前一刻。 JS 预编译、变量提升 创建 Active Object 对象,即执行期上下文。 寻找函数的形参和变量声明,将变量和形参名作为 AO 对象的属性名,值设定为 undefined. 将形参和实参相统一,即更改形参后的 undefined 为具体的形参值。 寻找函数中的函数声明,将函数名作为 AO 属性名,值为函数体。 JS 函数和变量声明提升 函数声明提升优先于变量声明 函数初始化也会提升 console.log(a); // [Function: a] var a = 1; console.log(a); // 1 function a() {} console.log(a); // 1 function b(a) { console.log(a); // [Function: a] var a = 2; console.log(a); // 2 function a() {} console.log(a); // 2 } b(3); this 指向 以函数的形式(包括普通函数、定时器函数、立即执行函数)调用时,this 的指向永远都是 window。 以方法的形式调用时,this 指向调用方法的那个对象 以构造函数的形式调用时,this 指向实例对象 以事件绑定函数的形式调用时,this 指向绑定事件的对象 使用 call 和 apply 调用时,this 指向指定的那个对象 箭头函数中 this 的指向会继承外层函数调用的 this 绑定(无论 this 绑定到什么) var name = "window"; var obj = { name: "obj", arrowFunc: () => { console.log(this, this.name); }, func: function () { console.log(this, this.name); }, }; function func() { console.log(this, this.name); } // Window "window" || Object "obj" || Window "window" func() || obj.func() || obj.arrowFunc(); call, apply, bind call func.call(thisArg, ...argArray); 调用一个函数,同时可以改变这个函数内部的 this 指向 实现继承 function Father(myName, myAge) { this.name = myName; this.age = myAge; }…