Typescript: TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression
Another possibility is to use a rest parameter instead of arguments
:
on(eventName:string, callback) {
this.socket.on(eventName, (...args) => {
this.$rootScope.$apply(() => {
callback.apply(this.socket, args);
});
});
}
An arrow function expression is a syntactically compact alternative to a regular function expression, although without its own bindings to the
this
,arguments
,super
, ornew.target
keywords.
But you can use function
instead of () =>
on(eventName:string, callback) {
var self = this;
this.socket.on(eventName, function() {
var args = arguments;
self.$rootScope.$apply(() => {
callback.apply(self.socket, args);
});
});
}