摘要://class里面可以放多个函数(类的多方法声明) class Coder{ // val是类函数的参数(函数的传参) name(val){ console.log(val); return val; } skill(val){ console.log(this.name('nl:')+':'+'Skill'+val...
阅读全文
摘要://promise let state=1; function step1(resolve,reject){ console.log('1.开始洗菜做饭'); if(state=1){ resolve('洗菜做饭完成') }else{ reject('洗菜做饭错误'); } } function step2(resolve,reje...
阅读全文
摘要://proxy 代理 增强对象和函数(方法) 生命周期 真正方法执行之前预处理 let obj={ add:function(){ return val+100; }, name:'I am jun' } console.log(obj.add(100)); console.log(obj.name); let pro=new Proxy({ a...
阅读全文
摘要://高效的map let json={ name:'nl', skill:'web' }; console.log(json.name); var map=new Map(); map.set(json,'iam'); console.log(map); //下面看下set里面设置一对key,value值 map.set('nl',json); console.log(map);...
阅读全文
摘要:// 总结:set和weakSet //Set数据结构 let setArr=new Set(['nl','web','css']); setArr.add('前端职场'); // has查找值 console.log(setArr); console.log(setArr.has('xiaodi')); // 删除并打印 setArr.clear(); console.log(setArr);...
阅读全文
摘要://Symbol多用于node.js let a=new String; let b=new Number; let c=new Boolean; let d=new Array; let e=new Object; //上面这些new出来的类型都是对象 let f=Symbol(); //打印出来的f是symbol类型(在控制台显示为红色) console.log(typeof (f)); ...
阅读全文
摘要:let name='jin'; let skill='web'; //ES6允许我们用变量的形式赋值 let obj={name,skill}; console.log(obj); //key值的构建 let key="skill"; var obj1={ [key]:'web' } console.log(obj1); //es5就有的自定义对象方法 let obj2={ ...
阅读全文
摘要://总结:下面是对象和数组的函数解构,in的用法,遍历数组的方法以及数组转换成字符串 //对象函数的解构json //以后不需要传递单个数据了,直接传递json对象就可以 let json={ a:'nl', b:'jun', c:'dq' } function fun(a,b='web'){ console.log(a,b); } fun(json); //数...
阅读全文
摘要://v-for key //'use strict'严谨模式时不能用默认值 function add(c,d=1){ if(c==0){ // 主动抛出异常 throw new Error('c is error'); } return c+b; } console.log(add(1)); //下面获得传递参数的个数指的是必须传递的参数(也就是会忽...
阅读全文
摘要:// json数组格式 let json={ // key:value '0':'nl', '1':'jun', '2':'ming', // length可见是json数组格式 length:3 } // 使用转换成数组的方法是Array.from()方法 let arr=Array.from(json); console.log(arr); ...
阅读全文
摘要:// 二进制声明binary let binary=0B010101; console.log(binary); // 八进制声明octal let octal=0o666; console.log(octal); // isFinite用来判断是不是数字 let a=11/4; console.log(Number.isFinite(a)); console.log(Number.isFin...
阅读全文
摘要:// 字符串模板 let nl="计算价格有错误"; let lg=9; let bg=3; let blog=`业务逻辑有bug,比如${nl},控制台是不会报错误的,这样的错误不好找。 bug有两种,一种是代码错误,一种是业务逻辑错误。前者比较好解决,后者是比较不容易找出来的。 计算结果:${lg*bg}`; document.write(blog); document.write(``);...
阅读全文
摘要:// 下面是对象扩展运算符 function jun(...arg){ console.log(arg[0]); console.log(arg[1]); console.log(arg[2]); // 下面的arg[3]没有值,但是不会报错 console.log(arg[3]); } jun(1,2,3) console.log("例子1:"); l...
阅读全文
摘要:// 看看下面的解构赋值的例子 let [a,[d,e]]=[0,[5,2]]; console.log(a); console.log(d); console.log(e); // 下面我们给变量一个默认值 let [foo='go']=[]; console.log(foo); // 左边默认赋值了,右边只需给没有值的赋值 let [x,y='na']=['jun']; console.l...
阅读全文
摘要:"use strict"; var a = "jun"; let b="li"; // console.log(a); // window.onload=function(){ // console.log(a); // } { // var是全局声明,会覆盖前面的var var a="君"; }
阅读全文