如何提升网页加载速度jquery
减小HTTP请求 网站建设中过多的图片,CSS、script、flash,会增长内容加载的请求负担,因此,建议您减小这类元素的使用。使用CSS合并图片,避免出现直接插入原图。ajax
JavaScript数据类型分那几种? 编程
1. Number 数字类型跨域
2. String 字符串类型浏览器
3. Boolean 布尔类型缓存
4. Function 函数闭包
5. Object 对象app
6. Nulljquery插件
7. Undefined 没有定义类型异步
function Animal() { this.feeling = 'happy'; } function Dog(name, variety) { this.name = name; this.variety = variety; } Dog.prototype = new Animal();//Animal实例对象就是Dog原型对象(Animal实例对象的prototype属性指向Animal的原型对象) Dog.prototype.constructor = Dog;//给Dog原型对象的constructor属性的指针从新指向构造函数Dog var dog = new Dog('二狗', '哈士奇'); print(dog.feeling); // happy
缺点:
a、当父包含引用类型属性时,该属性会被全部实例对象共享,示例代码以下:
function Animal() { this.colors = ['red', 'green', 'blue']; } function Dog() { } // 继承Animal Dog.prototype = new Animal(); Dog.prototype.constructor = Dog; var dog1 = new Dog(); dog1.colors.push('black'); print(dog1.colors); // red,green,blue,black var dog2 = new Dog(); print(dog2.colors); // red,green,blue,black
b、不能在不影响全部实例对象的状况下,向父级构造函数传递参数
function Dog(name, variety) { Animal.apply(this, arguments); this.name = name; this.variety = variety; } var dog = new Dog('二狗', '哈士奇'); print(dog.feeling); // happy
使用apply或者call方法改变构造函数做用域,将父函数的构造函数绑定到子对象上。虽然解决了子对象向父对象传递参数的目的,可是借助构造函数,方法都在构造函数中定义,函数的复用就无从谈起
3.构造函数和原型链组合继承
function Animal(name) { this.name = name; this.colors = ['red', 'green', 'blue']; } Animal.prototype.sayName = function() { print(this.name); }; function Dog(name, age) { // 继承属性 Animal.call(this, name); this.age = age; } // 继承方法 Dog.prototype = new Animal(); Dog.prototype.constructor = Dog; Dog.prototype.sayAge = function() { print(this.age); } var dog1 = new Dog('二狗', 1); dog1.colors.push('black'); print(dog1.colors); // red,green,blue,black dog1.sayName(); // 二狗 dog1.sayAge(); // 1 var dog2 = new Dog('二牛', 2); print(dog2.colors); // red,green,blue dog2.sayName(); // 二牛 dog2.sayAge(); // 2