Jump to content
bernhard

[solved] Weekend Challenge: RockTabulator needs JS Experts :)

Recommended Posts

Putting "use strict" should really be the default... It simply shows more hints and errors and this can be very useful while debugging. Using this in every JS file now revealed some data type mismatch too, when using !=== instead of !==. (see screenshots below)

In trash.js I changed basically these lines:

  var gridInstance = $('.RockTabulator.tabulator');
  var grid = RockTabulator.getGrid(gridInstance);

and further below:

        // success
                if(result.success) {
                    UIkit.notification(check + result.success, {timeout: 3000});
                    if( RockTabulator.getGrid(gridInstance).reload() ) {
                        console.log('grid has reloaded!');
                    } else {
                        console.log('grid has not reloaded!');
                    }
                    // grid.reload();
                }
      },

But as I said, since RT is not known inside that JS script, it can't call an unknown method getGrid...

lastonefortoday.PNG

  • Thanks 1

Share this post


Link to post
Share on other sites
19 hours ago, dragan said:

when using !=== instead of !==. (see screenshots below)

I don't understand what you mean. I also don't get all the errors shown in your screenshot. Or at least I don't know when they occur. Maybe you could do a short screencast?

I'm working on the subdir fix now...

Share this post


Link to post
Share on other sites

Now guess what @dragan ... I've changed nothing in my code. Just pulled the changes for the not supported subdir installations and everything just WORKS! 😮 

Share this post


Link to post
Share on other sites

@bernhard Perhaps go back to page 1 of this thread, i.e. this post.

a) I have inserted in all JS files "use strict" at the very top

b) I have replaced != with !== everywhere the IDE was warning me

tldr; "use strict" in JS is something like PW's debug mode enabled: it gives you many more errors, hints + warnings that otherwise would slip through (even if you end up with unexpected results). The Mozilla link I posted is a good read.

Share this post


Link to post
Share on other sites
7 minutes ago, bernhard said:

Just pulled the changes for the not supported subdir installations and everything just WORKS!

Great news! At least one ray of sunshine on this rainy miserable day 😄

Share this post


Link to post
Share on other sites
28 minutes ago, dragan said:

@bernhard Perhaps go back to page 1 of this thread, i.e. this post.

a) I have inserted in all JS files "use strict" at the very top

b) I have replaced != with !== everywhere the IDE was warning me

Thx, I've read all your posts and links. "use strict" atm breaks my module. I'll have a look into that.

I don't see any harm in using != instead of !== wherever I'm using it, but if you can explain why it should be a problem I'm happy to learn and change it.

trash.thumb.gif.a4118e605c48abfec6a3341bcf6eef00.gif

Share this post


Link to post
Share on other sites
22 hours ago, dragan said:

Yep: you should get used to use "use strict" in every JS file, then you would have found this error earlier: 

https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Strict_mode

Voila 🙂 https://github.com/BernhardBaumrock/RockTabulator/commit/6920de2120ade50099e269b6fa025acc98659d8a

Share this post


Link to post
Share on other sites
18 hours ago, dragan said:

@bernhard Perhaps go back to page 1 of this thread, i.e. this post.

a) I have inserted in all JS files "use strict" at the very top

b) I have replaced != with !== everywhere the IDE was warning me

tldr; "use strict" in JS is something like PW's debug mode enabled: it gives you many more errors, hints + warnings that otherwise would slip through (even if you end up with unexpected results). The Mozilla link I posted is a good read.

@bernhard the != or == comparison operator will simply check for a value no matter of the type in example checking against 1, '1', or true will always return true, whereas triple comparison operator will also check for type, therefore if a variable value was set to like var a = 1; checking against boolean like if(a === true) will return false because value of variable a is actually integer.
It's best practice using triple comparison operator but it also depends on situation if in example the type of value you are checking against is always known and you always expect it to be the same.

  • Thanks 1

Share this post


Link to post
Share on other sites

Thx for the explanation. I'm aware of that, but my question was more if there is a good reason in this special case why I should use !== instead of !=

I tend to use !== whenever it is NECESSARY (eg when doing strpos where a 0 is something different than FALSE) and != whenever it is not necessary. That way I know instantly that the type matters...

PS: Welcome to the forum 🙂 

  • Like 1

Share this post


Link to post
Share on other sites
6 hours ago, bernhard said:

I tend to use !== whenever it is NECESSARY

I do the opposite: I tend to use != and == when it is necessary, eg. when we are expecting multiple types and coercing can be harvested as a lazy programmer's tool 😛 

Remebering what != and == do can be a challenge: https://dorey.github.io/JavaScript-Equality-Table/

Edited by szabesz
typo
  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...