javascript类中的变量定义
我试图理解一个chrome扩展,它为html页面中的任何选定元素显示xpath。 我遇到了这个我无法理解的代码javascript类中的变量定义,javascript,google-chrome-extension,Javascript,Google Chrome Extension,我试图理解一个chrome扩展,它为html页面中的任何选定元素显示xpath。 我遇到了这个我无法理解的代码 'use strict'; // Extension namespace. var xh = xh || {}; xh.bind = function(object, method) { return function() { return method.apply(object, arguments); }; }; ////////////////////////
'use strict';
// Extension namespace.
var xh = xh || {};
xh.bind = function(object, method) {
return function() {
return method.apply(object, arguments);
};
};
////////////////////////////////////////////////////////////////////////////////
// xh.Bar class definition
xh.Bar = function() {
this.boundShowBar_ = xh.bind(this, this.showBar_);
this.boundHandleRequest_ = xh.bind(this, this.handleRequest_);
this.boundMouseMove_ = xh.bind(this, this.mouseMove_);
this.boundKeyDown_ = xh.bind(this, this.keyDown_);
chrome.extension.onMessage.addListener(this.boundHandleRequest_);
this.barFrame_ = document.createElement('iframe');
this.barFrame_.src = chrome.extension.getURL('bar.html');
this.barFrame_.id = 'xh-bar';
this.barFrame_.className = 'top';
this.barFrame_.style.height = '0';
// Temporarily make bar 'hidden' and add it to the DOM. Once the bar's html
// has loaded, it will send us a message with its height, at which point we'll
// set this.barHeightInPx_, remove it from the DOM, and make it 'visible'.
// We'll add it back to the DOM on the first bar request.
//this.barFrame_.style.visibility = 'hidden';
document.body.appendChild(this.barFrame_);
document.addEventListener('keydown', this.boundKeyDown_);
};
xh.Bar.prototype.active_ = false;
xh.Bar.prototype.barFrame_ = null;
xh.Bar.prototype.barHeightInPx_ = 0;
xh.Bar.prototype.currEl_ = null;
xh.Bar.prototype.boundHandleRequest_ = null;
xh.Bar.prototype.boundMouseMove_ = null;
xh.Bar.prototype.boundKeyDown_ = null;
bind函数到底在做什么?
调用bind时使用的方法没有在代码中的任何地方定义
bind(thisArg:Object,[param1:Object,[param2:Object,[…]]):Function
这看起来像是@NickVolynkin的一个问题,这将在代码审查中。这可能是一个有用的参考: