当前位置: 代码迷 >> JavaScript >> js 简单的this有关问题
  详细解决方案

js 简单的this有关问题

热度:159   发布时间:2013-03-01 18:33:02.0
js 简单的this问题

var BindAsEventListener = function(object, fun) {
return function(event) {
return fun.call(object, (event || window.event));
}
}

SimpleDrag.prototype = {
  //拖放对象,触发对象
  initialize: function(drag) {
this.Drag = $(drag);
this._x = this._y = 0;
this._fM = BindAsEventListener(this, this.Move);
this._fS = Bind(this, this.Stop);
this.Drag.style.position = "absolute";
addEventHandler(this.Drag, "mousedown", BindAsEventListener(this, this.Start));
  }}

this._fM = BindAsEventListener(this, this.Move);
这里的this指向的是SimpleDrag还是initialize
javascript this

------解决方案--------------------
var dragTest = new SimpleDrag("aElement");
则this指向新生成的这个dragTest。
  相关解决方案