addEventListener scope parameter

Post here your questions about the HTML5 / JavaScript for SFS2X

Moderators: Lapo, Bax

Hamster
Posts: 4
Joined: 07 Sep 2017, 11:09

addEventListener scope parameter

Postby Hamster » 07 Sep 2017, 11:20

What exactly means the 3rd parameter in addEventListener in the documentation named scope, which is in all examples set to this? What is it usage and why is it in the documentation as type Number?

For example:
sfs.addEventListener(SFS2X.SFSEvent.CONNECTION, onConnection, this);

In the documentation it says:

Parameters:
...
{Number} scope
The object that acts as a context for the event listener: it is the object that acts as a "parent scope" for the callback function, thus providing context (i.e. access to variables and other mehtods) to the function itself.


TIA
User avatar
Bax
Site Admin
Posts: 4327
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: addEventListener scope parameter

Postby Bax » 07 Sep 2017, 16:28

First of all, you are looking at the documentation of an older version of the JavaScript API.
If you are using SmartFoxServer 2X v2.13 (or later), you should use the API tagged as "w/ binary protocol", available here: http://www.smartfoxserver.com/download/sfs2x#p=client
The updated doc for the "binary" API is available here: http://docs2x.smartfoxserver.com/api-docs/jsdoc/client/

In any case that type "number" is wrong, it should be "object".
For more details on what the scope is, you will find a ton of resources online. For example this: https://www.w3schools.com/js/js_scope.asp
Paolo Bax
The SmartFoxServer Team
Hamster
Posts: 4
Joined: 07 Sep 2017, 11:09

Re: addEventListener scope parameter

Postby Hamster » 08 Sep 2017, 09:34

Thanks for your answer, I haven't seen the new documentation before.

The reason why I was asking this question is because I use the Javascript API with Angular2 and with Smartfox Typescript type definitions from Definitelly Typed found in their repository. Someone made a great job with this type definitions and according to the old documentation the addEventListener has it's 3rd parameter as Number, which causes error when using this at compile time.

The new documentation should fill the missing Types (addEventListener method is one without it), so the Typescript definition files can be corrected. This is also part of another conversation on this forum.

I think it would be very helpful to have a client native in AngularJS 1 (with Promises) and Angular2 (with Observables; has a method to make them from callables) instead of Javascript API's with callbacks, or at least a wrapper around the Javascript API (like here for AngularJS). Unfortunately I don't have the knowledge for this yet.
User avatar
Bax
Site Admin
Posts: 4327
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: addEventListener scope parameter

Postby Bax » 08 Sep 2017, 09:55

I'm sorry but we don't support specific frameworks. Our API is supposed to be as generic as possible, so everybody can use it with a little or no effort.
As it regards the type definitions, see the other post.
Paolo Bax
The SmartFoxServer Team

Return to “SFS2X HTML5 / JavaScript API”

Who is online

Users browsing this forum: No registered users and 1 guest