读《javaScript 语言精粹》3
来源:互联网 发布:程序员联合开发王 编辑:程序博客网 时间:2024/05/16 00:28
第五章 继承
1伪类 使用构造函数
var Mamal=function(name){this.name=name;};Mamal.prototype.get_name=function(){return this.name;}
构建一个实例,
var myMamal=new Mamal("herb the Mammal");var name=myMamal.get_name();
构建一个伪类继承Mamal,通过定义constructor并替换他的prototype为一个Mammal的实例。
var Cat =function(name){this.name=name;};
//替换Cat.prototype为一个实例Mamal
Cat.prototype=new Mamal();
扩充原型函数
Cat.prototype.say=function(){return "saying hello"||name;}//调用函数var mycat=new Cat(" henrietta");var says =mycat.say();var name =mycat.get_name();
对象说明符
使用参数时,
var myObj=marker(f,l,mc,s);//写成 var=myObj=maker({first:f,last:1,state: s,city:c});
2 原型
继承的第二种形式为,构造一个对象字面量,然后调用beget
var myMamal={name:"herb the Mammal",get_name:function(){return this.name;};}
var myCat=Object.beget(myMamal);//扩张mycat的属性myCat.name="Henrietta";myCat.say="hello world";还可以覆盖父类的方法myCat.get_name=function(){return this.saying+","+this.name;}
作用域
方法调用的实例,将 对象的this作用域,保存后用到函数中。
函数化
var mamal =function(spec){var that={};that.get_name=function(){return spec.spec.name;}return that;};var myMamal=mamal({ name:‘herb’});
通过调用函数,返回一个对象字面量的实例。
var cat=function(spec){//为spec扩展属性spec.say="hello world"; //转成一个新的对象字面量,只能通过方法来访问它的属性。var that=mamal(spec);//扩展或者覆盖方法 that.get_name=function(){return "override the method";}return that;};
使用super的方法。
Object.method('superior',function(name)){var that=this,method=that[name];return function{return method.apply(that,arguments);}};
部件
var event=function(that){var registry={};that.fire=function(){var arry,function,handler,i,type=event.type; if(registry.hasOwnProperty(type)){//处理逻辑}return this;}}
第六章 数组
数组字面量
var empty=[];
var numbers=['one','two','three','four','five'];
第七章 正则表达式
第八章 方法
Arrays, Object ,RegExp,Number,Function,String
0 0
- 读《javaScript 语言精粹》3
- 读《JavaScript语言精粹》1
- 读《JavaScript语言精粹》2
- 读《JavaScript语言精粹》杂谈
- 读《JavaScript语言精粹(修订版)》心得
- 《JavaScript语言精粹》读后笔记
- 《JavaScript语言精粹》笔记(3)--函数
- 《JavaScript语言精粹》读书笔记
- 《JavaScript语言精粹》读书笔记
- JavaScript语言精粹
- 函数 -- Javascript语言精粹
- javascript语言精粹
- javascript语言精粹----笔记
- 《JavaScript语言精粹》--JSLint
- javascript语言精粹-------------------------读书笔记
- JavaScript语言精粹(读书笔记)
- javascript语言精粹----笔记
- 《JavaScript语言精粹》笔记
- 数据结构三之线性表
- 【单片机从零进阶开发工程师4合1课程】全套130个实例
- LeetCode之Island Perimeter
- javaweb开发
- C语言运算符总结心得
- 读《javaScript 语言精粹》3
- 散列表1: 基于分离链接法的散列表
- java算法知识点解析(1):字符串操作
- Linq:对XML文档进行增、删、改、查询(一)
- Maven中的dependency的scope作用域详解
- markdown 设置字体、字号、颜色以及背景色
- LeetCode--No.74--Search a 2D Matrix
- linux(Centos)修改主机名的方法
- Linux初识(二)