I will be adding tricks to this series as I learn them. Keep in mind these tricks and tips are specifically for ES5.
Let’s directly dive in.
What you can do instead, is use IIFE pattern to initialize your members when the object is first created.
new Foo() it executes all the expressions in the function
Foo. But, adding IIFE to your code makes it more structured and is more readable.
2. Check if the argument is a Number
Let me know if you guys know any better way to do that.
3. Default Value
How do amateurs set default values?
How do professionals set default values?
How do legends set default values?
4. TRUE sort your arrays
If not, this is that moment.
To fix this below is the correct way to sort your numbers-
In ES6, it becomes sexier-
5. Disable Right click
Ever wanted to hide your implementation details from users?
Another simple hack to add to it is to disable right click on the page so that users are not able to inspect your web app.
Of course, there are other workarounds to get away this. But, for most of the naive users- this should do the trick.
oncontextmenu="return false" disables the right-click menu on your web page.
6. Load IE specific script or CSS sheet
I am sure your customer, at some point, has changed requirements on you to support the Internet Explorer browser. No one is so lucky not to. :(
Here’s how you can load files just for the Internet Explorer.
Well, it’s not limited to only IE. You can target any platform and write code specific to that platform. Isn’t that neat?!