nmbug.js: Use bind to avoid forwarding message_id through _get_tags
authorW. Trevor King <wking@tremily.us>
Sun, 21 Sep 2014 12:35:05 +0000 (05:35 -0700)
committerW. Trevor King <wking@tremily.us>
Sun, 21 Sep 2014 13:04:47 +0000 (06:04 -0700)
Instead of telling _get_tags that the callback will always want the
message_id (in addition to the list of that message's tags), use bind
[1] to add that information when we set the _edit_tags callback.

[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind

nmbug.js

index 2bbde9076acde4c5dc45e74473ae7f8732f5723e..8b8dcba3fb0a12c521dc61037e3cd04e735bad91 100644 (file)
--- a/nmbug.js
+++ b/nmbug.js
@@ -2,7 +2,7 @@ var nmbug_server = 'http://localhost:5000';
 
 nmbug = {
        show: function (message_id) {
-               this._get_tags(message_id, this._edit_tags.bind(this));
+               this._get_tags(message_id, this._edit_tags.bind(this, message_id));
        },
        _get_tags: function (message_id, callback) {
                var url = [
@@ -16,7 +16,7 @@ nmbug = {
                        if (this.status == 200) {
                                var tags = JSON.parse(this.response);
                                console.log('nmbug: got tags', tags);
-                               callback(message_id, tags);
+                               callback(tags);
                        } else {
                                throw 'Error fetching ' + url + ' (status ' + this.status + ')';
                        }