日期:2014-05-16  浏览次数:20404 次

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。