《javascript高级程序设计》第五章 reference types

第5 章 引用类型
5.1 Object 类型
5.2 Array 类型
  5.2.1 检测数组
  5.2.2 转换方法
  5.2.3 栈方法
  5.2.4 队列方法
  5.2.5 重排序方法
  5.2.6 操作方法
  5.2.7 位置方法
  5.2.8 迭代方法
  5.2.9 归并方法
5.3 Date 类型
  5.3.1 继承的方法
  5.3.2 日期格式化方法
  5.3.3 日期/时间组件方法
5.4 RegExp 类型
  5.4.1 RegExp 实例属性
  5.4.2 RegExp 实例方法
  5.4.3 RegExp 构造函数属性
  5.4.4 模式的局限性
5.5 Function 类型
  5.5.1 没有重载(深入理解)
  5.5.2 函数声明与函数表达式

  5.5.3 作为值的函数

  5.5.4 函数内部属性
  5.5.5 函数属性和方法
5.6 基本包装类型
  5.6.1 Boolean 类型
  5.6.2 Number 类型
  5.6.3 String 类型
5.7 单体内置对象
  5.7.1 Global 对象
  5.7.2 Math 对象

 

reference types:
有个部分location methods ,关于indexOf 和 lastIndexOf 的 ,还要看下中文解释

The Date Type  、The RegExp Type  都没有仔细看

The Function Type 当中:

function sum(num1, num2){
    return num1 + num2;
}
alert(sum(10,10)); //20
var anotherSum = sum;
alert(anotherSum(10,10)); //20
sum = null;
alert(anotherSum(10,10)); //20

----------------------------------------------------------------------假如改成如下的就会报错了,相当于一个执行前,一个执行后,但是为什么呢?

function sum(num1, num2){
    return num1 + num2;
}
var anotherSum = sum;
sum = null;
alert(anotherSum(10,10)); 

-----------------------------------------------------------------------
sort比较数字的例子,很常见,但是原理不太懂

 

String Location Methods
可以查找到字母在一句话中的位置:

var stringValue = “Lorem ipsum dolor sit amet, consectetur adipisicing elit”;
var positions = new Array();
var pos = stringValue.indexOf(“e”);

while(pos > -1){
        positions.push(pos);
        pos = stringValue.indexOf(“e”, pos + 1);
}
alert(positions); //”3,24,32,35,52”


------------------------------------------------------------------------------------------------------

var text = “cat, bat, sat, fat”;
result = text.replace(/(.at)/g, “word ($1)”);
alert(result); //word (cat), word (bat), word (sat), word (fat)

(假如把$1  换成是$2 , 或者是$0 都不是很有效的~)
$n  匹配第n个捕获组的子字符串  (2013.3.5)假如我想让$2 可以工作应该如何修改?

call 和 apply的用处(20130901)

除了传递参数
它们真正强大的地方是能够扩充函数赖以运行的作用域。

window.color = "red";
var o = { color: "blue" };
function sayColor(){
alert(this.color);
}
sayColor(); //red
sayColor.call(this); //red
sayColor.call(window); //red
sayColor.call(o); //blue
sayColor.call(o); //blue

当运行sayColor.call(o)时,函数的执行环境就不一样了,因为此时函数体内的this 对象指向了o,于是结果显示的是"blue"。
使用call()(或apply())来扩充作用域的最大好处,就是对象不需要与方法有任何耦合关系。

在9.9的周志里面也有对call的运用

posted @ 2013-09-01 20:43  星堡a  阅读(230)  评论(0编辑  收藏  举报