diff options
| author | Niklas Baumstark | 2012-01-25 01:22:19 +0100 |
|---|---|---|
| committer | Niklas Baumstark | 2012-04-10 23:58:07 +0200 |
| commit | d761e429f7c6b8583d32f7849fdbeb9aa2b50faf (patch) | |
| tree | 31c4f9304b0dc33755978bbfa3ce50f88f4af28e | |
| parent | a0d0d8ecfe40a1b802f72dff100185875ee63e2f (diff) | |
| download | vimium-d761e429f7c6b8583d32f7849fdbeb9aa2b50faf.tar.bz2 | |
introduce a utils helper for prototype inheritance
| -rw-r--r-- | lib/completion.js | 6 | ||||
| -rw-r--r-- | lib/utils.js | 8 |
2 files changed, 11 insertions, 3 deletions
diff --git a/lib/completion.js b/lib/completion.js index 6aec9e83..3c43f28b 100644 --- a/lib/completion.js +++ b/lib/completion.js @@ -410,7 +410,7 @@ var completion = (function() { AsyncFuzzyUrlCompleter.call(this); this.maxResults = maxResults || 1000; } - FuzzyHistoryCompleter.prototype = new AsyncFuzzyUrlCompleter; + utils.extend(AsyncFuzzyUrlCompleter, FuzzyHistoryCompleter); FuzzyHistoryCompleter.prototype.refresh = function() { this.resetCache(); this.fetchFromPort('getHistory', { maxResults: this.maxResults }, function(msg) { @@ -424,7 +424,7 @@ var completion = (function() { var FuzzyBookmarkCompleter = function() { AsyncFuzzyUrlCompleter.call(this); } - FuzzyBookmarkCompleter.prototype = new AsyncFuzzyUrlCompleter; + utils.extend(AsyncFuzzyUrlCompleter, FuzzyBookmarkCompleter); FuzzyBookmarkCompleter.prototype.refresh = function() { this.resetCache(); this.fetchFromPort('getAllBookmarks', {}, function(msg) { @@ -439,7 +439,7 @@ var completion = (function() { var FuzzyTabCompleter = function() { AsyncFuzzyUrlCompleter.call(this); } - FuzzyTabCompleter.prototype = new AsyncFuzzyUrlCompleter; + utils.extend(AsyncFuzzyUrlCompleter, FuzzyTabCompleter); FuzzyTabCompleter.prototype.createAction = function(match) { var open = function() { chrome.extension.sendRequest({ handler: 'selectSpecificTab', id: match.tab.id }); diff --git a/lib/utils.js b/lib/utils.js index 9b5cfcb9..7ed7c9ad 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -39,6 +39,14 @@ var utils = { return document.evaluate(xpath, document.documentElement, namespaceResolver, resultType, null); }, + /** Sets up prototype inheritance */ + extend: function(base, sub) { + function surrogateCtor() { } + surrogateCtor.prototype = base.prototype; + sub.prototype = new surrogateCtor(); + sub.prototype.constructor = sub; + }, + /** Creates a single DOM element from :html */ createElementFromHtml: function(html) { var tmp = document.createElement("div"); |
