上一页 1 ··· 5 6 7 8 9 10 11 12 下一页
摘要: //组合继承(有时候也较伪经典继承):将原型链和借用构造函数的技术组合到一块//思路:借用构造函数继承属性、原型链继承方法。避免了借用构造函数的原型方法不可复用,只有构造函数的属性可以复用的弊端function SuperType(name) { this.name = name; this.colors = ["red", "blue"];}SuperType.prototype.sayName = function () { alert(this.name);}function SubType(name, age) { //继承了SuperType2 阅读全文
posted @ 2013-07-07 15:35 金帛 阅读(169) 评论(0) 推荐(0)
摘要: //借用构造函数(constructor stealing),有时候也叫伪造对象或者经典继承//弊端:原型方法不可复用,只有构造函数的属性可以复用function SuperType() { this.colors = ["red", "blue"];}function SubType() { SuperType.call(this); //SuperType.apply(this);}var instance1 = new SubType();instance1.colors.push("black");console.log(in 阅读全文
posted @ 2013-07-06 15:56 金帛 阅读(170) 评论(0) 推荐(0)
摘要: function SuperType() { this.property = true;}SuperType.prototype.getSuperValue = function () { return this.property;}function SubType() { this.subproperty = false;}//继承了SuperTypeSubType.prototype = new SuperType();SubType.prototype.getSubValue = function () { return this. subproperty;}va... 阅读全文
posted @ 2013-07-06 15:40 金帛 阅读(213) 评论(0) 推荐(0)
摘要: /**直接创建原型方法与对象字面量创建原型方法的区别在于*直接创建原型方法:会在原有的原型上添加方法*对象字面量创建原型方法:直接替换原有的原型(会切断原型链)*///直接创建原型方法function Person(name, age) { this.name = name; this.age = age;}Person.prototype.sayName = function (){ alert(this.name);}Person.prototype.sayAge = function (){ alert(this.age);}var person = new Pe... 阅读全文
posted @ 2013-07-05 08:49 金帛 阅读(379) 评论(0) 推荐(0)
摘要: //理解各种方法和属性typeof、instanceof、constructor、prototype、__proto__、isPrototypeOf、hasOwnProperty、//1、typeof方法 获取变量的类型,返回:number, string, undefined, object, boolean, functionconsole.log("typeof方法");var st = "abcd";console.log(typeof st);//string 也可以用typeof(st);//2、instanceof方法 判断变量是否是某个对 阅读全文
posted @ 2013-06-19 18:51 金帛 阅读(296) 评论(0) 推荐(0)
摘要: //1、创建对象//缺点:创建很多个对象的时候会产生大量的代码var person = new Object();person.name = "Nicholas";person.age = 24;person.job = "码农";person.sayName = function () { alert(this.name);}//2、工厂模式//通过接收参数来构建一个包含所有必要信息的对象,节省了很多代码//缺点,没有解决对象识别的问题(对象的类型)function creatPerson(name, age, job) { var o = new O 阅读全文
posted @ 2013-06-19 17:58 金帛 阅读(278) 评论(0) 推荐(0)
摘要: //String类型//字符串位置方法console.log("字符串位置方法");//indexOf(),lastIndexOf():从一个字符串中搜索给定的子字符串,返回子字符串的位置(没有则返回-1)//用法 string.indexOf(str, location):str为子字符串,location为可选参数,表示从哪个位置开始搜索//indexOf()默认从开头向后搜索,返回第一个字符串的位置//lastIndexOf()默认从末尾向前搜索,返回第一个字符串的位置var stringValue = "hello world!";console 阅读全文
posted @ 2013-06-11 11:32 金帛 阅读(218) 评论(0) 推荐(0)
摘要: //1、Boolean类型:是布尔值对应的引用类型//和布尔值有点区别,typeof()返回的是Objectconsole.log("Boolean类型");var falseObject = new Boolean(false);var falseValue = false;console.log(typeof(falseObject));//objectconsole.log(typeof(falseValue));//booleanconsole.log(falseObject instanceof Boolean);//trueconsole.log(falseVa 阅读全文
posted @ 2013-06-09 21:46 金帛 阅读(560) 评论(0) 推荐(0)
摘要: //length属性:表示函数希望接收的命名参数的个数//prototype属性:保存所有实例方法的地方,如toString()和valueOf()都保存在prototype下console.log("函数的属性length,prototype");function sayName(name) { alert(name);}function sum(num1, num2) { return num1 + num2;}function sayHi() { alert('hi');}console.log(sayName.length);//1console.l 阅读全文
posted @ 2013-06-09 19:47 金帛 阅读(361) 评论(0) 推荐(0)
摘要: getByClass: function (oParent, sClass) {//class选择器 var aChild = oParent.getElementsByTagName('*'); var result= []; var re = new RegExp('\\b' + sClass + '\\b', 'i'); for (var i=0; i<aChild.length; i++) { if (re.test(sClass)) { result.push(aChild[i... 阅读全文
posted @ 2013-06-09 17:23 金帛 阅读(135) 评论(0) 推荐(0)
上一页 1 ··· 5 6 7 8 9 10 11 12 下一页