Javascript "use strict" in Ionic apps?


#1

Hi, having seen many Ionic-related starter apps, Git repos, sample apps and so on, I noticed that (almost) nobody is using ES5 “use strict”.

Just for this reason I’m also not using it, but does anyone know why this doesn’t seem to be common practice with Ionic apps? Maybe just coincidental but if anyone has experiences (good or bad) with “use strict” then I’d love to know.


#2

"use strict" is used just to make sure you write what is considered more ‘secure’ JavaScript code. It basically just means you can’t use undeclared variables as well as a few other features.

Explanation here: http://www.w3schools.com/js/js_strict.asp


#3

Thanks, yes I know … I just noticed that in all of the code of Ionic apps nobody seems to use it, that’s all. But probably it’s just to reduce some clutter in demo code.


#4

Yeah I think it’s usually just because people don’t tend to stick to writing that strict and don’t often include it because the code can run the same with or without it. I guess it probably is best to use it as a means of best practice though.


#5

we are using it in our apps + eslint to jslint…

Big advantage --> everyone in the company is writing the same code-style without defining long lists of coding guidelines for such things. … and the best case would be --> everybody understands the code of the others


#6

Cool I’m using jshint in my gulp-build as well.

I’ll consider adding ‘use strict’.

By the way, then I suppose you use Immediately-Invoked Function Expressions (IIFE’s) and put “use strict” as the first line within that.


#7

i have a requirejs environment, where all files are wrapped in define / require blocks and you code is defined as a callback - so i have already wrapped everything in a function :slight_smile:


#8

Okay I see, I’m not using that but I heard about it.

Does that have advantages in terms of performance or something like that?


#9

What we need is an Ionic Style Guide: http://robferguson.org/2015/07/10/ionic-style-guide/


#10

Nice blog, only the post titled “style guide” isn’t really a Style Guide. But since an Ionic app is an Angular app I think we can utilize one of the angular style guides (e.g. John Papa’s) ? And for the rest the various “starter apps” help a lot.

I think the Ionic team can still do things here e.g. in the form of providing some more advanced starter apps (with a better gulp file, require.js and so on) and a set of “best practices”.

Ionic’s misson is to make stuff easy and indeed it is easy (for a simple app) but there’s still room for improvement.