摘要: function Person(age){ var name = "Lala"; //私有变量 this.age = age; //公有变量 this.getName = function(){ //公有函数 return name; }}var p1... 阅读全文
posted @ 2014-12-04 16:52 lcw5945 阅读(125) 评论(0) 推荐(0) 编辑
摘要: 内存管理是很重要的一部分,系统分配给浏览器的内存空间很少,如果不能很好的管理内存很可能因为某个页面导致浏览器的崩溃。虽然js有垃圾回收机制,但是在程序中如果不用的对象,要及时释放引用等待gc回收js垃圾回收的机制1. 标记清除当变量进入环境时,将变量标记"进入环境",当变量离开环境时,标记为:"离开... 阅读全文
posted @ 2014-12-04 15:47 lcw5945 阅读(400) 评论(0) 推荐(0) 编辑
摘要: this 通常是指当前实例对象,每个函数在被调用时,会自动创建2个特殊变量,this和arguments ,他们只活动在函数内部,不会访问外部。var name = "glob this";var obj={ name : "obj this", getName : function()... 阅读全文
posted @ 2014-12-04 14:57 lcw5945 阅读(99) 评论(0) 推荐(0) 编辑
摘要: function createClose(){ var r = new Array(); for (var i = 0; i"); } return r;}// alert(createClose());var funs = createClose();document.wr... 阅读全文
posted @ 2014-12-04 14:34 lcw5945 阅读(126) 评论(0) 推荐(0) 编辑
摘要: 编译参数加上:-defaults-css-url default.css然后建个default.css 文件放到src根目录 阅读全文
posted @ 2014-12-04 11:53 lcw5945 阅读(151) 评论(0) 推荐(0) 编辑
摘要: //对象克隆function object(o){function F(){}F.prototype = o;return new F();}//原型继承function inheritPrototype(subType,superType){var prototype = object(super... 阅读全文
posted @ 2014-12-04 11:50 lcw5945 阅读(100) 评论(0) 推荐(0) 编辑
摘要: 此方式即可满足函数的复用,也可满足子类实例有各自的属性,也可传递参数。function SuperType(name){ this.name = name; //参数传递 this.colors = [1,2]; //子类实例共有基本值} SuperType.prototype.sayN... 阅读全文
posted @ 2014-12-04 11:48 lcw5945 阅读(151) 评论(0) 推荐(0) 编辑
摘要: function SuperType(){this.colors = [1,2,3];} function SubType(){//继承属性SuperType.call(this);} var in1 = new SubType();in1.colors.push(4);alert(in1.colo... 阅读全文
posted @ 2014-12-04 11:47 lcw5945 阅读(113) 评论(0) 推荐(0) 编辑
摘要: function SuperType(){this.property = true;}SuperType.prototype.getSuperValue = function(){return this.property;}function SubType(){this.subproperty = ... 阅读全文
posted @ 2014-12-04 11:45 lcw5945 阅读(106) 评论(0) 推荐(0) 编辑
摘要: 原型中的方法是共享的,如果每次创建构造函数时不必在重新在原型中添加方法function Person(name,age){ this.name = name; this.age = age; //方法 if(typeof this.sayName != "function") { ... 阅读全文
posted @ 2014-12-04 11:44 lcw5945 阅读(124) 评论(0) 推荐(0) 编辑
摘要: 对实例中属性或者方法的访问时,先从实例的对象中寻找,如果不存在则在原型中寻找。所以:如果原型中有某个属性,在实例对象中在重写则会隐藏原型的属性访问。function Person(){}Person.prototype.name = "Jack";Person.prototype.sayName =... 阅读全文
posted @ 2014-12-04 11:43 lcw5945 阅读(177) 评论(0) 推荐(0) 编辑
摘要: static prototype:Object函数的原型是静态的,也就是一个函被创建无论多少次原型是一个如果将属性和方法添加到原型中,则所有函数对象都会共有这些属性和方法function Person(){}Person.prototype.name = "Jack";Person.prototyp... 阅读全文
posted @ 2014-12-04 11:41 lcw5945 阅读(122) 评论(0) 推荐(0) 编辑
摘要: 函数是对象,每个函数都是Function类型的实例,函数名只是一个指向函数对象的指针。function sum(){} == sum = function(){};function sum(p1,p2){ return p1+p2;}alert(sum(10,10)); // 20var sum1 ... 阅读全文
posted @ 2014-12-04 11:39 lcw5945 阅读(115) 评论(0) 推荐(0) 编辑