Questions tagged [javascript]

JavaScript (not to be confused with Java) is a high-level, dynamic, multi-paradigm, weakly-typed language used for both client-side and server-side scripting. Use this tag for questions regarding common implementations of ECMAScript, JavaScript, JScript, etc. JS does not typically refer to its ECMA-cousin, ActionScript.

Filter by
Sorted by
Tagged with
15
votes
6answers
26k views

Is it better to put the JS code on the html file or in an external file?

If I'm designing a one page website, is it better to create external file for my JS code, or just put it in the html code? Is putting it on the page faster to load? Can I change the permissions to ...
15
votes
5answers
11k views

Why is extending the DOM/built-in object prototypes a bad idea?

I'm looking for a definitive answer to why extending built-in prototypes is so heavily chastised in the JS developer community. I've been using the Prototype JS framework for a while, and to me doing [...
15
votes
1answer
5k views

Why doesn't ES6 have thin-arrow functions?

ES6 added fat-arrow functions (=>), which have two major differences from normal functions: shorter syntax (including implicit return if you use a single-expression body) inherit this from ...
15
votes
6answers
4k views

How risky is it to use Coffeescript without knowing Javascript? [closed]

I'm a reasonably experienced programmer trying to learn web developement. I'm trying to develop a client-side web application which uses svg or canvas for graphics. I've decided I'd like to write ...
15
votes
1answer
829 views

When to use prototypical programming in JavaScript

I've spent a good bit of time developing simple widgets for projects in the following way: var project = project || {}; (function() { project.elements = { prop1: val1, prop2: val2 } ...
15
votes
0answers
744 views

Is there a reason for not using JavaScript for direct database connections on a web site? [duplicate]

I am thinking about using JavaScript for direct connection to our database server. I think I have solutions to all the possible problems about it. Security: Modern database management systems support ...
14
votes
5answers
6k views

Why is JavaScript not used for classical application development (compiled software)? [closed]

During my years of web development with JavaScript, I come to the conclusion that it's an incredible powerful language, and you can do amazing things with it. It offers a rich set of features, like: ...
14
votes
2answers
2k views

How Do News Websites E.g. Forbes / Zdnet Seamlessly Merge One Webpage into Another?

If you go to E.g: http://www.forbes.com/sites/adrianbridgwater/2015/06/12/why-technology-has-to-be-continuous/ OR http://www.zdnet.com/article/if-you-want-those-cool-ios-9-features-its-time-to-buy-a-...
14
votes
5answers
2k views

What is the benefit of having “no runtime exceptions”, like Elm claims?

Some languages claim to have "no runtime exceptions" as a clear advantage over other languages that has them. I am confused on the matter. Runtime exception is just a tool, as far as I know, and ...
14
votes
4answers
31k views

What is a good IDE for client side JavaScript development? [closed]

I recently started learning JavaScript and am looking for a good JavaScript Editor/IDE. I found dozens of them in a Google search but I would appreciate if users who have experience with using such an ...
14
votes
8answers
4k views

Five or fewer tips to writing good JavaScript? [closed]

JavaScript has obviously become pretty indispensable; however, I'm still new to it, and I've found it's hard to fight the feeling that it seems such a mess and I don't want to deal with it right now. ...
14
votes
5answers
13k views

XSLT equivalent for JSON

I was interested in finding (or if necessary developing) an XSLT equivalent for JSON. As I have not found any, I was considering the possible query language to use for matching JSON paths so as to ...
14
votes
3answers
3k views

why is the latter function 10% faster although it must create the variables over and over again?

var toSizeString = (function() { var KB = 1024.0, MB = 1024 * KB, GB = 1024 * MB; return function(size) { var gbSize = size / GB, gbMod = size % GB, mbSize = gbMod /...
14
votes
4answers
1k views

Using natural language grammar in fluent API

I'm tinkering with a query abstraction over WebSQL/Phonegap Database API, and I find myself both drawn to, and doubtful of, defining a fluent API that mimics the use of natural English language ...
14
votes
4answers
7k views

Where should I do localization (server-side or client-side)?

I am currently developing a new web application based on a rich JavaScript client which communicates with multiple REST web services on my server. That application is intended to be used in at least ...
14
votes
1answer
835 views

Does the “function returning function” pattern have a name in JavaScript?

I use this pattern quite often in JavaScript. Here is an example: const comments = [ { text: 'Hello', id: 1 }, { text: 'World', id: 4 }, ]; const byId = id => element => element.id === id; ...
14
votes
3answers
850 views

I'm losing track of the flow of my PHP web app, it's becoming hard to work with

I've been programming for a few years, and have become very familiar with C# and JavaScript over time. I have some larger C# and JavaScript projects that I have no trouble navigating around. I ...
14
votes
5answers
14k views

Pure Front end JavaScript with Web API versus MVC views with ajax

This was more a discussion for what peoples thoughts are these days on how to split a web application. I am used to creating an MVC application with all its views and controllers. I would normally ...
14
votes
1answer
5k views

How can NodeJS be “non-blocking”?

I'm learning NodeJS and just wanted to clarify something. In several introductory tutorials and books so far, very early on they've described Node's "non-blocking" architecture - or rather that it's ...
14
votes
5answers
2k views

In API design, when to use/avoid ad hoc polymorphism?

Sue is designing a JavaScript library, Magician.js. Its linchpin is a function which pulls a Rabbit out of the argument passed. She knows its users may want to pull a rabbit out of a String, a Number,...
14
votes
6answers
5k views

How do I make sense of the javascript frameworks explosion ? Should I learn them all? [closed]

For a beginner web developer who is still doing web development the conventional way (PHP/J2EE/Struts on server side, HTML/CSS/Javascript on client side), I was bowled over by the recent blog post on ...
14
votes
2answers
3k views

Where does jQuery fit-in with frameworks like JavaScriptMVC, BackboneJS, SproutCore and Knockout?

I have been happily using JQuery for the last 2 years and have been quite sucessful creating some really cool functionality with it...so I am very comfortable with it. I also beleive the future of ...
14
votes
1answer
6k views

Legal ramifications of use of the JavaScript trademark?

It's widely known that the name "JavaScript" is trademarked by Oracle (formerly a trademark of Sun, formerly a trademark of Netscape). However, others seem to have no problem using the JavaScript ...
14
votes
3answers
5k views

Does react.js make sense for a static content-driven site?

I'm pretty sold on the react.js model because it makes DOM manipulation so smooth and comprehensible. But I'm wondering how it could be leveraged for a site that's largely static with big blocks of ...
14
votes
3answers
3k views

How to write manageable code with functional programming?

I just started with functional programming (with JavaScript and Node.js) and from the look of things it looks as if the code I am writing would grow to be one hell of a code base to manage, when ...
13
votes
14answers
30k views

I can't remember programming 5 mins after learning? [closed]

I'm learning Java, and I found a great teacher. He explains everything perfectly. I understand it all. My problem, is that after learning a short section, for example "Nested If Statements" or "Many ...
13
votes
7answers
3k views

What constitutes “improper use” of the javascript Eval feature? [closed]

Eval is a notoriously controversial language feature. Douglas Crockford flat out rejects it. I'm wondering what specific risks Eval brings about. According to this question, Improper use of eval ...
13
votes
5answers
2k views

Genetic programming [closed]

I recently was browsing Reddit and came across a post linking to a "JavaScript genetic algorithm" example. I've really been fascinated with the concepts of genetic algorithms and programming, however ...
13
votes
5answers
1k views

Can *any* program task be expressed without state?

This is a theoretical question, but after many years of programming in what I now realize is "normal" imperative technique, using C++ mainly, I've discovered this other world of functional programming,...
13
votes
2answers
7k views

Comma as a separator vs. comma as a delimiter

In this video, the speaker says: "Some people get confused about how commas work. They think they should be delimiters rather than separators. Now you can think about them either way." I don't ...
13
votes
4answers
3k views

Why is HTML/Javascript minification beneficial

Why is HTML/Javascript minification beneficial when the HTTP protocol already supports gzip data compression? I realize that Javascript/HTML minification has the potential to significantly reduce ...
13
votes
2answers
9k views

Responsive Web Design vs. User-Agent Sniffing

The CSS3 media query feature has led to many interesting possibilities in terms of developing websites which adjust to many different screen sizes and devices. However, in practice, I'm starting to ...
13
votes
2answers
30k views

How do you change how intellij auto formats code? [closed]

IntelliJ does some odd formatting with Javascript code and I am trying to figure out how to get it to stop formatting this way. Whenever I chain jQuery functions together, it over indents the auto ...
13
votes
3answers
1k views

Providing Local JS and CSS Resources for CDN Fallbacks

Given that CDNs are a Good Thing because they can serve resources closer to the client, the client can cache them, and you can reduce load on your own server. In recent browsers, loading resources ...
12
votes
6answers
2k views

Javascript naming conventions

I am from Java background and am new to JavaScript. I have noticed many JavaScript methods using single character parameter names, such as in the following example. doSomething(a,b,c) I don't like ...
12
votes
3answers
981 views

Unit Testing Competition

My employers runs a monthly unit testing day competition. One entire day is dedicated to writing unit tests -- obviously we do more testing throughout the month, but this is an entire day -- and the "...
12
votes
1answer
5k views

What does Google mean here when they say “don't copy and paste this code”?

Here is an excerpt from code from Google's recaptcha API (https://www.google.com/recaptcha/api.js): /* PLEASE DO NOT COPY AND PASTE THIS CODE. */ (function() { if (!window['___grecaptcha_cfg']) { ...
12
votes
6answers
1k views

What is the term used to describe a function/method that modifies the object it's called on?

Sorry for the generic question. I have searched all over and found so many threads similar to this, however not one that answers my specific question - perhaps because the term I'm looking for doesn't ...
12
votes
1answer
5k views

In what case would indexedDB be useful [duplicate]

I have been over-viewing indexedDB recently, and I cannot seem to find a suitable use case that would not be better done using a server side database. Since the little hackathon competition I'm doing ...
12
votes
6answers
7k views

A testing environment for JavaScript other than browser? [closed]

When I want to test something in JavaScript, I open up a new browser window (mostly Firefox) and start writing code in the provided console (mostly Firebug). However, this tends to be really tedious ...
12
votes
4answers
1k views

What are the Advantages of a “Combined” Getter/Setter VS Individual Methods?

This is what I call a "combined" getter/setter method (from jQuery): var foo = $("<div>This is my HTML</div>"), myText; myText = foo.text(); // myHTML now equals "This is my HTML" (...
12
votes
4answers
2k views

Is there a better way of writing unit tests than a series of 'AssertEquals'?

Here's a basic example of what my unit test needs to be, using qunit: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <...
12
votes
1answer
893 views

Google Blink (new WebKit fork): Meaning of “Moving DOM into Javascript”?

From the Blink Blog: Finally we’d like to explore even larger ideas like moving the entire Document Object Model (DOM) into JavaScript. What does this mean? Does it mean WebKit's DOM is currently ...
12
votes
1answer
5k views

What is the difference between web components and custom elements?

"Web Components" and "Custom elements" are often mixed up, and web searches for the title of this question don't yet produce much clarity. Let's fix that.
12
votes
2answers
13k views

Webkit as GUI in .Net/Mono

I want to make a cross platform application, which will also have a website where the desktop applications (Windows, iOS, Linux) will talk to the server and keep the users data in sync. So far the ...
12
votes
6answers
7k views

How are large JavaScript applications supposed to be structured?

I've recently been shown some JavaScript plugins written for OBIEE Mobile App Developer, as well as some custom libraries for various projects. Coming from an OOP background, I am a little confused ...
12
votes
3answers
3k views

Different callbacks for error or error as first argument?

We (and the JS SO chat room) had a talk with @rlemon some days ago about his Little-XHR library about error handling. Basically, we wanted to decide which error handling pattern should be used: xhr....
12
votes
3answers
1k views

What should be tested in Javascript?

At work, we've just started on a heavily Javascript based application (actually using Coffeescript, but still), of which I've been implementing an automated test system using JsTestDriver and fabric. ...
12
votes
2answers
11k views

Find the new coordinates using a starting point, a distance, and an angle

Okay, say I have a point coordinate. var coordinate = { x: 10, y: 20 }; Now I also have a distance and an angle. var distance = 20; var angle = 72; The problem I am trying to solve is, if I want ...
12
votes
3answers
6k views

Object Oriented Programming in JavaScript. Is there life without it? [duplicate]

At our company we have pretty large body of PrototypeJS based JavaScript code, which we are porting to jQuery for several reasons (not really important here). I'm trying to set up coding guidelines to ...