如javascript
var arrayList = ['a','b','c','d','e','f'];
怎么清空 arrayList
html
arrayList = [];
arrayList.length = 0;
arrayList.splice(0, arrayList.length);
function isArray(obj){ return Object.prototype.toString.call( obj ) === '[object Array]'; }
__proto__
是指向构造函数的 prototype
属性。function isArray(obj){ return obj.__proto__ === Array.prototype; }
function isArray(obj){ return $.isArray(obj) }
function uniq(array){ var temp = []; //一个新的临时数组 for(var i = 0; i < array.length; i++){ if(temp.indexOf(array[i]) == -1){ temp.push(array[i]); } } return temp; } var aa = [1,2,2,4,9,6,7,5,2,3,5,6,5]; console.log(aa) console.log(uniq(aa))
function Parent(){ this.name = 'wang'; } function Child(){ this.age = 28; } Child.prototype = new Parent();//继承了Parent,经过原型 var demo = new Child(); alert(demo.age); alert(demo.name);//获得被继承的属性
事件委托,就是某个事件原本该本身干的,可是本身不干,交给别人来干,就叫事件委托。打个比方:一个button对象,原本本身须要监控自身的点击事件,可是本身不来监控这个点击事件,让本身的父节点来监控本身的点击事件。前端
B,新添加的元素还会有以前的事件java
闭包就是可以读取其余函数内部变量的函数ajax
通俗的讲:就是函数a的内部函数b,被函数a外部的一个变量引用的时候,就建立了一个闭包。正则表达式
// 建立新节点 createDocumentFragment() //建立一个DOM片断 createElement() //建立一个具体的元素 createTextNode() //建立一个文本节点 // 添加、移除、替换、插入 appendChild() removeChild() replaceChild() insertBefore() //在已有的子节点前插入一个新的子节点 // 查找 getElementsByTagName() //经过标签名称 getElementsByName() //经过元素的Name属性的值(IE容错能力较强,会获得一个数组,其中包括id等于name值的) getElementById() //经过元素Id,惟一性
==判断内容是否相等不比较类型编程
console.log(1=="1");//true
===判断内容相等且类型也相等json
console.log(1==="1"); //false
function A(name){ this.name = name; this.sayHello = function(){alert(this.name+” say Hello!”);}; } function B(name,id){ this.temp = A; this.temp(name); //至关于new A(); delete this.temp; this.id = id; this.checkId = function(ID){alert(this.id==ID)}; }
function stopBubble(e) { if (e && e.stopPropagation) e.stopPropagation() else window.event.cancelBubble=true } return false
四、函数没有返回值时,默认返回undefined。数组
二、做为对象原型链的终点。安全
json(JavaScript Object Notation)是一种轻量级的数据交换格式。它是基于JavaScript的一个子集。数据格式简单,易于读写,占用带宽小
如:{"age":"12",""}
json字符串转换为json对象
var obj=eval('('+str+')'); var obj=str.parseJSON(); var obj=JSON.parse(str);
JSON对象转换为JSON字符串
var last=obj.toJSONString(); var last=JSON.stringify(obj);
Array.prototype.unique1 = function () { var n = []; //一个新的临时数组 for (var i = 0; i < this.length; i++) //遍历当前数组 { //若是当前数组的第i已经保存进了临时数组,那么跳过, //不然把当前项push到临时数组里面 if (n.indexOf(this[i]) == -1) n.push(this[i]); } return n; } Array.prototype.unique2 = function() { var n = {},r=[]; //n为hash表,r为临时数组 for(var i = 0; i < this.length; i++) //遍历当前数组 { if (!n[this[i]]) //若是hash表中没有当前项 { n[this[i]] = true; //存入hash表 r.push(this[i]); //把当前数组的当前项push到临时数组里面 } } return r; } Array.prototype.unique3 = function() { var n = [this[0]]; //结果数组 for(var i = 1; i < this.length; i++) //从第二项开始遍历 { //若是当前数组的第i项在当前数组中第一次出现的位置不是i, //那么表示第i项是重复的,忽略掉。不然存入结果数组 if (this.indexOf(this[i]) == i) n.push(this[i]); } return n; }