Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
when I do not want to use a transpiler. I want to write straight Javascript? For example if I feature detect that let is available, so what I can not re-write my code to use block level scoping.
For example when should I start using let? Is it even possible to form a general strategy?
Feature detection doesn't really work for syntax. While you can test for syntax features using eval and try...catch, you cannot use that information to write your code one way or the other. It also doesn't really make sense to write the same code twice but with different syntax.
If you don't want to use a transpiler, you will simply have to avoid using any ES6 features until your target audience uses browsers that support it.
Is it even possible to form a general strategy?
One way would be to say that you are going to use feature X if Y% of your visitors use a browser that support it. But that also means that your site might not properly work for (100-Y)% of your visitors.
That's exactly the problem transpilers are solving...
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
Is there a standard way (or ways) of packaging a Javascript GUI control such that it is easy for others to use and evaluate?
For example - should classes be named a certain way, should certain methods always be implemented?
Is a raw Javascript GUI control easy to use, or should it have a wrapper to make it usable in a framework? Currently, the code is not written for any framework.
Some background: I am a long time C# (WinForms) developer. To learn Javascript/HTML5, I ported one of my C# GUI projects, a spiral-shaped slider/track-bar, to Javascript and implemented a test harness using a HTML page. My plan is to use JSDoc to generate documentation once the classes/methods are stable.
Thanks in advance for any guidance.
There are a few best practices:
Use as few dependencies as possible.
Dependencies increase the package size and add the possibility that someone up the chain will insert a vulnerability. One dependency may be including a dozen more.
Don't put things in the global scope.
You can't trust other modules not to collide with you. If you must, pick a unique name.
Set "use-strict".
Use strict forces the browser to use more precise interpretation of your code. It can reduce errors and boost performance.
Don't eval.
While not necessarily evil, it's dangerous and often is a shortcut to doing something right.
As with all best practices, there are cases to ignore each of these.
There are some common patterns that js elements use when attaching to a page. Most typical is for an element that most closely matches the behavior is added to the document with a class that the script recognizes. For example <input type="number" class="praise-helix"></input>. HTML5 also supports custom data attributes, meaning that this is valid <input type="number" data-helix></input>.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I was wondering if there was any way for me to run older versions of javascript in the web browser!
I have apps that require ECMAScript 3 that broke and I was wondering if there was anyway to run older versions without a polyfill library!
While it works fine, I want it to use ECMAScript 3 for functions like goto and such
JavaScript does not have, and has never had, goto.
and I dislike using the newer keywords.
Whatever you mean by "newer keywords", if you dislike using them, then don't use them.
Does anyone know of a way to use older ECMAScript/JavaScript versions?
Yes, use any current ES/JS version, since they are all completely backward compatible for all practical purposes.
Take a look at Babel, it's a traspiler of Js to Js, you can set the enter version and the out version and it's easy to setup.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'll keep my question short. I've read this question about a delay function.
How to wait 5 seconds with jQuery?
and it struck me that people wanted to know about alternative ways to achieve this using JQuery.
In my understanding JQuery is nothing but a JS library. In many cases to introduce new functionality.
Now why would someone use JQuery if an original JS function is available and not even too complex?
Bonus question: Can JS functions be called from within JQuery? (this one, if negative might answer my first one, actually...)
In my understanding JQuery is nothing but a JS library. In many cases to introduce new functionality.
Yes, that is correct. In fact, your astute observation that people want to use jQuery where JS will suffice likely stems from a lack of understanding to this point!
Now why would someone use JQuery if an original JS function is available and not even too complex?
Someone may wish to use jQuery for certain functions if the JS-only equivalent is not well supported in all browsers.
Bonus question: Can JS functions be called from within JQuery? (this one, if negative might answer my first one, actually...)
Certainly! As you stated, jQuery is just a JavaScript library, and can be mixed with bits of plain JS without a problem.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Javascript : What are the different conditions when javascript work in IE but not in Firefox or some other browser?
one that i know of is that while using certain window events..
What other scenarios can cause javascript to not work properly?
The answer is too complex to fully list here. Use sites like http://caniuse.com that will tell you which JavaScript is available in which browser.
Generally speaking, all browsers implement JavaScript differently. Microsoft have long been stuck in their own world, implementing their own ways to do things, whereas everyone else seems to try and conform to the standards as much as possible. Microsoft are coming around to the "standards" way of doing things, and from what I hear, IE11 will be a massive step in this direction.
As already mentioned, you can use http://caniuse.com/ to find what you can and can't do in different browsers, but then you'll likely end up doing what many others have done...write your own API which works around these to achieve a task...which is a bit unnecessary, unless you can find a ground-breaking way to implement your API that will be beneficial to other developers.
APIs like jQuery already work around these differences. The aim with these libraries is to provide clean JavaScript, whilst being completely transparent from the underlying JavaScript implementation.
Also, look into "shim"/"polyfill" implementations. These are used when a core feature that is recognised as part of an ECMAScript version has not been implemented in the browser. These provide the implementation for you, if it is not natively supported.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Where I was working as an intern, working on a JavaScript front end project with Backbone.JS, I was using those getters and setters as provided by the framework (Backbone) but was asked to define my own to make it clear whats public/private. I was more for using those provided by the backbone. Whats the better practice or recommended method here?
Then recently, I was developing my own ExpressJS/Mongoose app, I started off thinking I define a Todo model then a Todos collection that exposes functions like byId, byList etc, but then I was thinking perhaps I should just use those provided by Mongoose?
The advantage of using the provided getters/setters will be
Less code, less bugs
standard way of getting/setting. Instead of 2 (from framework + custom)
Another developer will just need to learn the framework instead of my custom code to understand whats happening
Cons:
a little longer code
less sense of whats private whats not, but I think this is not very important ... esp in a dynamic language
Again, whats recommended here?
If the framework allows it to you, write your own getters/setters only when you have to modify the behaviour of the default getters/setters.
There's no reason to write them if not needed, IMHO.