Bug #2347

'this.xxx' is returning undefined in onEvent scope (api v1 duktape)

Added by Leonid Protasov over 6 years ago. Updated over 6 years ago.

Status:FixedStart date:11/07/2014
Priority:NormalDue date:
Assignee:Andreas Smas% Done:

100%

Category:API
Target version:4.8
Found in version:Latest BE Platform:Linux

Description

            item.onEvent("addFavorite", function(item) {
            var entry = {
                url: this.url,
                title: this.station,
                station: this.station,
                description: this.description,
                format: this.format,
                bitrate: this.bitrate
            };
            var list = eval(store.list);
                    var array = [showtime.JSONEncode(entry)].concat(list);
                    store.list = showtime.JSONEncode(array);
            showtime.notify("'" + this.station+ "' has been added to My Favorites.", 2);
            });

History

#1 Updated by Andreas Smas over 6 years ago

 item.onEvent("addFavorite", function(item) {
            var entry = {
                url: this.url,
                title: this.station,
                station: this.station,
                description: this.description,
                format: this.format,
                bitrate: this.bitrate
            };
            var list = eval(store.list);
                    var array = [showtime.JSONEncode(entry)].concat(list);
                    store.list = showtime.JSONEncode(array);
            showtime.notify("'" + this.station+ "' has been added to My Favorites.", 2);
            }.bind(item));

Try binding the callback to the item?

or I think you can just use item. directly instead of this. ?

#2 Updated by Leonid Protasov over 6 years ago

  • Status changed from New to Fixed
  • % Done changed from 0 to 100

Bind does magic. Closing this.

Also available in: Atom PDF