发表于: 2017-03-02 01:16:15
2 1238
今日完成
1任务4,获得了一个定制的状态机。还是玩不转,
var singleState = { //定义有限状态机,是个对象,两个方法.beKill将其杀死
initialize: function(){ //初始化,在调用的时候使用
var self=this;//什么被call,什么就是this,而非function本身,更不是singleState.
self.currentState="alive";//初始 状态alive
console.log(self.currentState);////
self.click(singleState.beKill); //绑定点击事件/
},
beKill: function () {if(this.currentState!="dead")this.currentState!="dead"}//
};
singleState.initialize.call(dom);//
2 this的指代问题://然而我还是看不懂
*全局函数,内的this,指代全局对象。
function
test(){
this
.x = 1;
alert(
this
.x);
}
test();
// 1
*全局对象,内的this,指代上级对象
var o = {};
function test(){alert(this.x); }
o.x = 1;
o.m = test;
o.m(); // 1
*作为构造函数调用,this指代new出的对象
function test(){this.x = 1; }
var o = new test();
alert(o.x); // 1
var x = 2;
function test(){this.x = 1; }
var o = new test();
alert(x); //2
*.apply 调用 ,apply方法作用是改变函数的调用对象,此方法的第一个参数为改变后调用这个函数的对象,this指代第一个参数
var x = 0;
function test(){alert(this.x); }
var o={};
o.x = 1;
o.m = test;
o.m.apply(); //0
o.m.apply(o); //1
3 小的知识点
方法:在对象里面定义的function
function什么时候用(),什么时候不用。----有()是运行此函数,没有则是对应函数的指针。
关于函数:函数 实际上 是 对象。 每个 函数 都是 Function 类型 的 实例, 而且 都与 其他 引用 类型 一样 具有 属性 和 方法。 由于 函数 是 对象, 因此 函数 名 实际上 也是 一个 指向 函数 对象 的 指针, 不会 与 某个 函数 绑 定。
使用var构造函数。
明日计划:
1 任务4,做出本地存储的代码和修改本地存储的逻辑部分。如果有可能,把状态机用上。
2 this相关基础知识,准备小课堂。
问题:所谓无处着力,只是不着力而已。
收获:各种逻辑,复习了一些基础知识,以及零碎的知识点。
评论