摘要: 方法就是把函数放在对象的里面,对象只有两个东西:属性和方法 var li = { name:'li', birth:2000, age:function(){ var now = new.Date().getFullYear(); return now - this.birth; } } //属性 阅读全文
posted @ 2023-06-10 14:58 李鑫地图 阅读(13) 评论(0) 推荐(0)
摘要: 在JavaScript中,var定义变量实际是有作用域的。 假设在函数体中声明,则在函数体外不可以使用,(非要想实现的话,后面可以研究 一下 闭包) function li(){ var x = 1; x = x+1;//2 } x = x + 2;//uncaught ReferenceError 阅读全文
posted @ 2023-06-10 14:43 李鑫地图 阅读(13) 评论(0) 推荐(0)
摘要: 函数 定义方式一 绝对值函数 function abs(x){ return x; }else{ return -x; } 一旦执行到return代表函数结束,返回结果。 如果没有执行return,函数执行完也会返回结果,结果就是undefined 定义方式二 var abs = function( 阅读全文
posted @ 2023-06-10 14:25 李鑫地图 阅读(8) 评论(0) 推荐(0)
摘要: //ES6 Map var map = new Map([["tom",100],["jack",100],["jj",100]]); var name = map.get("tom");//通过key获取value map.set(‘admin’,123456);//新增或修改 map.delet 阅读全文
posted @ 2023-06-10 08:43 李鑫地图 阅读(12) 评论(0) 推荐(0)
摘要: if判断 var age = 1; if (age>3){ alterr("haha"); }else if{age<5){ alert("kuwa"); }else{ alert("kuwa"); } while循环,避免程序死循环 while(age<100){ age = age + 1; c 阅读全文
posted @ 2023-06-10 08:34 李鑫地图 阅读(8) 评论(0) 推荐(0)