js知识点--自看

1.鼠标滚轮事件

2.this指向问题(apply)

window.onload=function(){
            'use strict';
                //利用apply改变this指向
            // function getAge (){
            //     var y=new Date().getFullYear();
            //     return y-this.birth;
            // };
            // var xiaoming={
            //     name:"xiaoming",
            //     birth:1990,
            //     age:getAge
            // };
            // console.log(xiaoming.age());
            // //getAge.apply(xiaoming,[]); //this指向xiaoming, 参数为空

            var xiaoming = {
            name: '小明',
            birth: 1990,
            age: function () {
                 var _this = this;
                 console.log(this);//age的内部函数this指向xiaoming
                function getAgeFromBirth() {
                    var y = new Date().getFullYear();
                    console.log("内部this:"+this);//函数内部定义的函数,this指向undefined
                    return y - _this.birth;
                }
                return getAgeFromBirth();
            }
            };

            console.log(xiaoming.age());
        }

 

posted @ 2015-06-24 21:24  越来越好888  阅读(140)  评论(0)    收藏  举报