My first modal app - how to close the window?

Started by ubacher, June 04, 2017, 06:28:53 PM

Previous topic - Next topic

ubacher

I used the App Wizard to create my first modal app.

Where it says "Add your code here" I just put
console.Log ('Hello")

I tried putting Imatch.modalClose() after to close the window
but I get an error saying Imatch is not defined.
??????????
In the firefox debug console I get:
jQuery.Deferred exception: Imatch is not defined @http://127.0.0.1:50519/user/%20MarkPano/index.html:43:19
j@http://127.0.0.1:50519/system/jquery/dist/jquery.min.js:2:29946
g/</k<@http://127.0.0.1:50519/system/jquery/dist/jquery.min.js:2:30262
updateInfo/<@http://127.0.0.1:50519/user/EU-App2/index.html:142:24
j@http://127.0.0.1:50519/system/jquery/dist/jquery.min.js:2:29946
g/</k<@http://127.0.0.1:50519/system/jquery/dist/jquery.min.js:2:30262
undefined

thrinn

I think it is IMatch.modalClose() (with a uppercase IM), isn't it?
Thorsten
Win 10 / 64, IMatch 2018, IMA

ubacher

Thanks thrinn, that was it.
Why the Code editor lets me type this I don't understand? I thought in an up-to-date programming environment
one should not be able to make such mistakes undetected.
Maybe there is a setting in the editor which I have wrong?

Mario

Quote from: ubacher on June 05, 2017, 06:56:17 AM
Thanks thrinn, that was it.
Why the Code editor lets me type this I don't understand? I thought in an up-to-date programming environment
one should not be able to make such mistakes undetected.
Maybe there is a setting in the editor which I have wrong?

How should a mere text editor know that you are using a method name of a class that does not exist somewhere? JavaScript is case-sensitive, like most proper programming languages. Imatch.bla is not the same as IMatch.bla or iMatch.bla.

Since JavaScript is an interpreted language, your typo will only be caught at the time when JavaScript is trying to execute your code and too lookup the method. When it cannot find it, it will halt and dump the error message to the console. Remember that JavaScript can create functions at runtime, which means that your code is calling a function which does not yet exist...

Static code analysis can help with that. I recommend you install the ESLint extension (free) for Visual Studio. This is one of the many, many super-useful extensions for Visual Studio Code. ESList adds static code checking. It works similar to a spell checker, just that it understands JavaScript and an outline typos, non-existing classes or functions and things like that. For details, see http://eslint.org/

Click the on the Extensions button in the Activity Bar on the left side of Visual Studio Code to see which extensions are installed, and which you can add. Type eslint into the search box at the top toi find it. See image below.

Visual Studio Code is a powerful editor. But it becomes even more powerful by the many cool extensions you can install. From spell checkers to linting, there are thousands of free extension available.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

ubacher

In Basic we had the Option Explicit - I assume ESLint will kind of replace this.

I will get ESLint and learn using it.




Mario

No much to learn. It's basically automatic.

In JavaScript you can use

'use strict';

which is somewhat similar to Option Explicit. See https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Strict_mode
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook