-
特殊运算符的种类: 1、条件运算符 c?a:b c为true 则取a,否则取b 2、逗号运算符 a,b 例如 var s = (1,2,3),则s依次赋值,最后输出为3 3、delete运算符 delete obj.x 删除对象obj中的x属性 在IE9下,obj中必须configurable:true 才可以删除,否则无效 4、in运算符 判断obj是否有值或window里是否有变量,返回布尔值 例如 attr in json 或 'document' in window 5、instanceof 判断对象类型 {} instanceof Object // true 6、new运算符 创建一个新对象 new obj / new array ... 7、this对象 全局用指向window,函数内指向函数本身,浮动指针 8、typeof 判断对象,返回对象类型 例如 typeof 100 === 'number' // true 9、void 一元的,判断所有值,返回均为undefined查看全部
-
数组: 1、JS中的数组是弱类型的 数组中可以含有不同类型的元素 数组元素甚至可以是对象 或者其他数组; 2.创建 2.1 字面量 var arr = ['ds','aa']; 2.2 new Array构造器 var arr = new Array(); var arr = new Array(10); 则表示该数组有10个空元素(只有一个值的时候表示有多少元素) var arr = new Array('a','b'); 等价于 ['a','b']; new 是可以省略的 3.数组的读写 数组元素增减 用delate可以删除元素,但是数组长度不变,其实delate之后,是设置元素的值为undefined。 arr.push(1); 在数组尾部添加元素 arr.unshift();在数组头部添加元素 delete arr[2]; 是将数组中的下标为2的元素 变成undefined 并非真正的删除 arr.pop() 删除数组的最后一个元素 arr.shift() 删除数组的第一个元素 数组迭代 for循环 for in 遍历(定义在原型上的属性也会遍历出来) 使用hasOwnProperty可以避免将原型上的属性遍历出来 for(i in arr){ if(arr.hasOwnProperty(i)) //不会遍历出原型上的元素 }查看全部
-
Object.getOwProertyDescriptor(obj,property_name);<br> value: 属性值 writable: 该属性是否可写,可改变<br> enumerable:该属性是否可被枚举,就是可在for in中出现<br> configurable: 该属性的标签是否可改变,是否可用delete将该属性删除。 用defineProperty定义属性时,默认configurable为true,如果设置为false后,该属性不管是什么方式都无法更改。查看全部
-
this指向: 1、直接调用函数(<function>()):this指向全局对象。 2、方法调用模式(<object>.<function>()):this指向调用者<object>。 3、构造函数调用模式(obj = new <function>()):this指向被构造者obj。 4、apply/call/bind方法:this指向方法的第一个参数。 5、严格模式下,this不允许指向全局对象,此时this值为undefined。查看全部
-
懒人看过来!!!!!!!!!!!!!!!!!!!!! function Person(name,age) { this.name = name; this.age = age; } Person.prototype.hi = function () { console.log("hi,my name is "+this.name+"I'm"+this.age+"years old now."); } Person.prototype.LEG_NUM = 2; Person.prototype.ARMS_NUM = 2; Person.prototype.walk = function () { console.log(this.name+"is walking"); } function Student(name,age,className) { Person.call(this,name,age); this.className = className; } Student.prototype = Object.create(Person.prototype); Student.prototype.constructor = Student; Student.prototype.hi = function () { console.log("Hi,my name is"+this.name+",I'm"+this.age +"years old now,and from"+this.className); } Student.prototype.learn = function (subject) { console.log(this.name + "is learning" +subject+"at" +this.className) } //test var bosn = new Student('Bosn',23,'Class 3,Grade 2'); bosn.hi(); bosn.LEG_NUM; bosn.walk(); bosn.learn('math');查看全部
-
str是string(基本类型),本身是没有方法的。 当尝试把基本类型的str当做对象一样访问时,例如:str.length; 解释器会创建一个临时的包装对象,伪代码: [[tempObj]] = new String(str); [[tempObj]].length; // 返回具体的length; delete [[tempObj]]; // 销毁临时对象 重复访问str.length会重复创建这个临时对象。 所以str.t赋值可以成功,但再次访问str.t返回undefined,因为每次创建的临时包装对象都是不同的。查看全部
-
全局对象中的this指的是window对象,但是在严格模式下时undefined. 在对象中对象方法中的this值得是当前的对象,或者把函数作为对象的方法是用this都是指当前对象. 对象原型链上的方法中的this也指的是当前对象。 对象中的get/set方法中的this也指的是当前对象。 构造器中的this指的是构造器函数prototype中的原型,当new一个对象时就会将构造器的prototype中的this赋值个当前对象查看全部
-
var arraySimilar=function(){ var arr1 = [3,true,"abc",null,"bcd"]; var arr2 = ["uio",false,"qw",12,null]; var arr3 = new Array(); var arr4 = new Array(); var flag = false; if(arr1.length==arr2.length){ for(var i = 0 ; i<arr1.length; i++){ arr3[i]=typeof arr1[i]; arr4[i]=typeof arr2[i]; } arr3.sort(); arr4.sort(); for(var i = 0 ; i<arr1.length; i++){ if(arr3[i] == arr4[i]){ flag = true ; }else{ flag = false ; break; } } if(flag){ document.write("通过"); }else{ document.write("类型对比不通过"); } }else{ document.write("长度不同"); } }();查看全部
-
类型检测五种操作符: 1.typeof适用于检测基本类型和函数function,如typeof "123"返回“string”,typepeof Student(Student是已定义的函数)返回“function”,但是typeof null是个例外,为了解决兼容性的问题,不是返回“null”,而是返回“object” 2.instanceof适用于检测原生对象 如: function Student(){} function People(){} Student.prototype=Person() //Student的原型指向person() 对象的原型 var one=Student(); one instanceof Student//one的原型指向Student返回true one instanceof Person//one的原型先指向Student的原型,发现不对, 原型链上移,指向Person的原型,返回true 3.Object.prototype.toString().apply[[Class]],适用于内置对象 和基本类型,遇到Undefined和null失效(IE678返回"[object Object]") ,如Object.prototype.toString().apply([1,2,3])返回 "[object Array]" 4.constructor 5.duck type查看全部
-
in 和 hasOwnProperty in是判断该对象是否具有所要查找的属性 而hasOwnProperty则是判断该对象的实例是否具有所要查找的属性 因此可以自定义一个查找对象属性所在位置的函数: function hasProperty(obj,property){ return obj.hasOwnProperty(property) && property in obj; }//返回true时表示该属性在它的实例上,否则就在原型上查看全部
-
字符串类似数组,但不可像数组那样改写,要改写需用call查看全部
-
bind this查看全部
-
call和apply查看全部
-
OOP和正则的章节PPT似乎没上传啊?查看全部
-
数组元素的增删 arr.push(); 在数组的末尾添加一个元素 arr.unshift();在数组的第一个元素之前添加一个元素 delete arr[2]; 删除数组指定的元素,实际上是将指定的元素用 undefined 代替 arr.pop(); 删除数组最后一个元素 arr.shift(); 删除数组第一个元素查看全部
举报
0/150
提交
取消