js学习20150420(七)

一、

构造函数:就是普通函数,因为用途

工厂模式:
    原料->加工产品->出厂

工厂模式缺点:
1. 没有new
2. 每个对象拥有自己单独一个方法

new到底干嘛?
1. 自动帮你创建一个空白对象,并且赋值给this
2. 自动帮你返回this

* new后面跟的永远是 构造函数(函数)

* 默认情况下,全局都属于window

    js本身语言bug
    
    提出:严格模式
    'use strict'

    严格模式:
    a).修复局部函数 this
    b).定义变量必须加var
    c).不允许你在iffor等写函数的定义
    d).干掉with

1. instanceof: 检测自己父级,父级的父级...
2. constructor:构造器是谁, 直接父级

    如何检测一个对象是否是json?

二、

调this
this:当前方法属于谁,只看调用
    只管一层
this优先级:
new  object
定时器    window
事件    
方法
其他

三、

function show(){
    alert(this);    
}
//show(); //window
var arr=[1,2,3];
arr.show=show;
//show();
//arr.show();  //arr

//alert(new arr.show());

document.onclick=arr.show;


//document.onclick();  //document

//setTimeout(show,300);  //window
//setTimeout(arr.show,300);  //window
//setTimeout(document.onclick,300);  //window

//new show();  //object
//new arr.show(); //object
//new document.onclick(); //object

//setTimeout(new show,300); //object
//setTimeout(new arr.show,300);  //object
setTimeout(new document.onclick,300);  //object

setTimeout(function(){
    arr.show();
},300);

三、

2015-3-8  以面向对象的方式再来一次选项卡

四、

原文地址:https://www.cnblogs.com/king-bj/p/4414861.html