use ES5 bind() instead of lang.bind()

This commit is contained in:
Fabian Jakobs 2010-12-15 11:43:02 +01:00
commit 69095379c3
5 changed files with 43 additions and 35 deletions

View file

@ -65,10 +65,10 @@ var Editor =function(renderer, doc) {
}); });
var mouseTarget = renderer.getMouseEventTarget(); var mouseTarget = renderer.getMouseEventTarget();
event.addListener(mouseTarget, "mousedown", lang.bind(this.onMouseDown, this)); event.addListener(mouseTarget, "mousedown", this.onMouseDown.bind(this));
event.addMultiMouseDownListener(mouseTarget, 0, 2, 500, lang.bind(this.onMouseDoubleClick, this)); event.addMultiMouseDownListener(mouseTarget, 0, 2, 500, this.onMouseDoubleClick.bind(this));
event.addMultiMouseDownListener(mouseTarget, 0, 3, 600, lang.bind(this.onMouseTripleClick, this)); event.addMultiMouseDownListener(mouseTarget, 0, 3, 600, this.onMouseTripleClick.bind(this));
event.addMouseWheelListener(mouseTarget, lang.bind(this.onMouseWheel, this)); event.addMouseWheelListener(mouseTarget, this.onMouseWheel.bind(this));
this.$selectionMarker = null; this.$selectionMarker = null;
this.$highlightLineMarker = null; this.$highlightLineMarker = null;
@ -128,26 +128,26 @@ var Editor =function(renderer, doc) {
this.doc = doc; this.doc = doc;
this.$onDocumentChange = lang.bind(this.onDocumentChange, this); this.$onDocumentChange = this.onDocumentChange.bind(this);
doc.addEventListener("change", this.$onDocumentChange); doc.addEventListener("change", this.$onDocumentChange);
this.renderer.setDocument(doc); this.renderer.setDocument(doc);
this.$onDocumentModeChange = lang.bind(this.onDocumentModeChange, this); this.$onDocumentModeChange = this.onDocumentModeChange.bind(this);
doc.addEventListener("changeMode", this.$onDocumentModeChange); doc.addEventListener("changeMode", this.$onDocumentModeChange);
this.$onDocumentChangeTabSize = lang.bind(this.renderer.updateText, this.renderer); this.$onDocumentChangeTabSize = this.renderer.updateText.bind(this.renderer);
doc.addEventListener("changeTabSize", this.$onDocumentChangeTabSize); doc.addEventListener("changeTabSize", this.$onDocumentChangeTabSize);
this.$onDocumentChangeBreakpoint = lang.bind(this.onDocumentChangeBreakpoint, this); this.$onDocumentChangeBreakpoint = this.onDocumentChangeBreakpoint.bind(this);
this.doc.addEventListener("changeBreakpoint", this.$onDocumentChangeBreakpoint); this.doc.addEventListener("changeBreakpoint", this.$onDocumentChangeBreakpoint);
this.selection = doc.getSelection(); this.selection = doc.getSelection();
this.$desiredColumn = 0; this.$desiredColumn = 0;
this.$onCursorChange = lang.bind(this.onCursorChange, this); this.$onCursorChange = this.onCursorChange.bind(this);
this.selection.addEventListener("changeCursor", this.$onCursorChange); this.selection.addEventListener("changeCursor", this.$onCursorChange);
this.$onSelectionChange = lang.bind(this.onSelectionChange, this); this.$onSelectionChange = this.onSelectionChange.bind(this);
this.selection.addEventListener("changeSelection", this.$onSelectionChange); this.selection.addEventListener("changeSelection", this.$onSelectionChange);
this.onDocumentModeChange(); this.onDocumentModeChange();
@ -284,7 +284,7 @@ var Editor =function(renderer, doc) {
var tokenizer = mode.getTokenizer(); var tokenizer = mode.getTokenizer();
if (!this.bgTokenizer) { if (!this.bgTokenizer) {
var onUpdate = lang.bind(this.onTokenizerUpdate, this); var onUpdate = this.onTokenizerUpdate.bind(this);
this.bgTokenizer = new BackgroundTokenizer(tokenizer, this); this.bgTokenizer = new BackgroundTokenizer(tokenizer, this);
this.bgTokenizer.addEventListener("update", onUpdate); this.bgTokenizer.addEventListener("update", onUpdate);
} else { } else {

View file

@ -38,7 +38,6 @@
define(function(require, exports, module) { define(function(require, exports, module) {
var oop = require("pilot/oop"); var oop = require("pilot/oop");
var lang = require("pilot/lang");
var dom = require("pilot/dom"); var dom = require("pilot/dom");
var event = require("pilot/event"); var event = require("pilot/event");
var EventEmitter = require("pilot/event_emitter").EventEmitter; var EventEmitter = require("pilot/event_emitter").EventEmitter;
@ -55,7 +54,7 @@ var ScrollBar = function(parent) {
this.width = dom.scrollbarWidth(); this.width = dom.scrollbarWidth();
this.element.style.width = this.width; this.element.style.width = this.width;
event.addListener(this.element, "scroll", lang.bind(this.onScroll, this)); event.addListener(this.element, "scroll", this.onScroll.bind(this));
}; };
(function() { (function() {

View file

@ -38,7 +38,6 @@
define(function(require, exports, module) { define(function(require, exports, module) {
var oop = require("pilot/oop"); var oop = require("pilot/oop");
var lang = require("pilot/lang");
var dom = require("pilot/dom"); var dom = require("pilot/dom");
var event = require("pilot/event"); var event = require("pilot/event");
var GutterLayer = require("ace/layer/gutter").Gutter; var GutterLayer = require("ace/layer/gutter").Gutter;
@ -85,7 +84,7 @@ var VirtualRenderer = function(container, theme) {
this.layers = [ this.$markerLayer, textLayer, this.$cursorLayer ]; this.layers = [ this.$markerLayer, textLayer, this.$cursorLayer ];
this.scrollBar = new ScrollBar(container); this.scrollBar = new ScrollBar(container);
this.scrollBar.addEventListener("scroll", lang.bind(this.onScroll, this)); this.scrollBar.addEventListener("scroll", this.onScroll.bind(this));
this.scrollTop = 0; this.scrollTop = 0;
@ -101,8 +100,8 @@ var VirtualRenderer = function(container, theme) {
self.$loop.schedule(self.CHANGE_FULL); self.$loop.schedule(self.CHANGE_FULL);
}); });
event.addListener(this.$gutter, "click", lang.bind(this.$onGutterClick, this)); event.addListener(this.$gutter, "click", this.$onGutterClick.bind(this));
event.addListener(this.$gutter, "dblclick", lang.bind(this.$onGutterClick, this)); event.addListener(this.$gutter, "dblclick", this.$onGutterClick.bind(this));
this.$size = { this.$size = {
width: 0, width: 0,
@ -111,7 +110,7 @@ var VirtualRenderer = function(container, theme) {
scrollerWidth: 0 scrollerWidth: 0
}; };
this.$loop = new RenderLoop(lang.bind(this.$renderChanges, this)); this.$loop = new RenderLoop(this.$renderChanges.bind(this));
this.$loop.schedule(this.CHANGE_FULL); this.$loop.schedule(this.CHANGE_FULL);
this.$updatePrintMargin(); this.$updatePrintMargin();

View file

@ -65,22 +65,38 @@ if (!Object.keys) {
} }
if (!Function.prototype.bind) { if (!Function.prototype.bind) {
// From Narwhal // from MDC
Function.prototype.bind = function () { // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind
var args = Array.prototype.slice.call(arguments); Function.prototype.bind = function () {
var slice = [].slice;
var args = slice.call(arguments, 1);
var self = this; var self = this;
var bound = function () { var nop = function () {};
return self.call.apply(
self, // optimize common case
args.concat( if (arguments.length == 1) {
Array.prototype.slice.call(arguments) var bound = return function() {
) return fcn.apply(this instanceof nop ? this : obj, arguments);
); };
}; }
else {
var bound = function () {
return self.apply(
this instanceof nop ? this : ( obj || {} ),
args.concat( slice.call(arguments) )
);
};
}
nop.prototype = self.prototype;
bound.prototype = new nop();
// From Narwhal
bound.name = this.name; bound.name = this.name;
bound.displayName = this.displayName; bound.displayName = this.displayName;
bound.length = this.length; bound.length = this.length;
bound.unbound = self; bound.unbound = self;
return bound; return bound;
}; };
} }

View file

@ -82,12 +82,6 @@ exports.escapeRegExp = function(str) {
return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1'); return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
}; };
exports.bind = function(fcn, context) {
return function() {
return fcn.apply(context, arguments);
};
};
exports.deferredCall = function(fcn) { exports.deferredCall = function(fcn) {
var timer = null; var timer = null;