一只叫花花的小小鸟

导航

函数的定义和声明以及this

this = $(this)[0];

 

var person = {

  name : "lisa",

  age : "20",

  init : function(){

    alert(this.name);//this指的是person,包含name,age两个属性和一个init方法。

  }

}

 

function person(){

  this.name = "lisa";

  this.age = "20";

}

person.init = function(){(匿名函数,赋值给了person的init)

  var _this = this;//this指的是person,包含name,age两个属性和一个init方法。

  say(_this.name);

}

function say(a){//该函数不属于person,只是供person的成员函数init调用。(普通函数)

  alert(a);

}

 

var  person = function(name){

  this.name = name;

}

person.prototype.say = function(){

  return this.name;

}

posted on 2016-08-20 13:25  一只叫花花的小小鸟  阅读(202)  评论(0编辑  收藏  举报