diff options
| author | jez | 2011-01-04 16:59:50 +0800 |
|---|---|---|
| committer | jez | 2011-01-04 16:59:50 +0800 |
| commit | 92a0c80a4820689b14aaf1b7f0dda59de9417ac7 (patch) | |
| tree | e0eb5d2854fcadefc20da6b1da725b711545e7ae /lib/utils.js | |
| parent | bbf078cf0a3bff06a9fc2172b3b63e1198a42c4e (diff) | |
| download | vimium-92a0c80a4820689b14aaf1b7f0dda59de9417ac7.tar.bz2 | |
Factor out invokeCommandString.
Had to make 'this' point explicitly to 'window'.
Diffstat (limited to 'lib/utils.js')
| -rw-r--r-- | lib/utils.js | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/utils.js b/lib/utils.js index 4c05610c..7fc2a6b9 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -38,4 +38,17 @@ var utils = { } return result; }, + + /* + * Takes a dot-notation object string and call the function + * that it points to with the correct value for 'this'. + */ + invokeCommandString: function(str, argArray) { + var components = str.split('.'); + var obj = window; + for (var i = 0; i < components.length - 1; i++) + obj = obj[components[i]]; + var func = obj[components.pop()]; + return func.apply(obj, argArray); + }, }; |
