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
0
votes
2answers
60 views

How inject a collaborator who needs a back reference into a constructor

Following Hevery's advice to inject collaborators into constructor rather than new'ing things within constructor body, how gracefully do this when a collaborator needs a back reference to its owner, ...
7
votes
3answers
13k views

Why do browsers leak memory?

A colleague and I were speaking about browsers (using a browser control object in a project), and it appears as plain as day that all browsers (Firefox, Chrome, IE, Opera) display the same ...
0
votes
0answers
250 views

Front-end-side encryption: Where to store password throughout session?

currently we're working on a small application where we store a bunch of JSON data coming from a JS-based graphing editor (think of a spiced-up version of this) in a Rails-based backend. We want to ...
1
vote
1answer
1k views

Is it a good practice to log client side errors to a file

I basically want to know if it is considered a good practice to persist the errors that happen on the client side of a web application (typescript/angular for example) by logging them to files? Or if ...
2
votes
1answer
59 views

Realtime Live Auto updates for web applications

It's about trying to understand the architecture behind how updates to web application is done. I've been working on a non-public website that has bunch of records displayed in a UI, now the ...
4
votes
1answer
666 views

Visitor pattern. Operating on the nodes of a tree

I am working with jQuery like elements from the cheerio library to manipulate SVG images. These objects represent XML nodes and have a hierarchical internal structure. I am writing a function (in ...
4
votes
3answers
3k views

Declaring JS Functions in Two Ways : What's the Benefit?

I've come across JS code in which I see functions being declared in two different styles: Method 1 function doSomething(){ alert('This is one way of declaring a function'); } Method 2 ...
0
votes
1answer
170 views

Develop for MySQL and SQLite3 Concurrently

I am developing a javascript (Node.js) desktop program that works with an existing MySQL database. I would like to (eventually) distribute to others with based on SQLite, or MySQL if they need (or ...
1
vote
2answers
1k views

Best Practices - Including endpoint URL calls in JavaScript vs backend calls

I am building a web application that will retrieve results from a remote server and use them to render some charts and maps. The remote server has already been implemented and contains a large amount ...
1
vote
1answer
152 views

Is it a good practice to use jQuery object to load scripts onto page?

I am writing a website, and I've come up with quite a few scripts taking up a lot of space and ruining the aesthetics of my code. I came up with the idea of creating one script that fills a div below ...
2
votes
1answer
286 views

Is it a best practice to use a mocking service for testing http requests?

Is it better to unit test using a mock library like 'nock' (nodejs) or to just test the server's http requests directly? Here is an example of my Express server test for testing if my server is up ...
3
votes
1answer
2k views

JavaScript functional conversion from flat list to tree

I've been going through the RxJS tutorials http://reactivex.io/learnrx/. Almost all of the exercises involve moving from a hierarchical structure to a flat structure so I thought I'd try to do the ...
1
vote
0answers
114 views

ES6(babel): Best practice for create class

I have a Product class. When I attempt to reference this from within a method on the class, I get an error saying this is undefined. To solve this, I have to bind this to all methods. And this, for ...
4
votes
1answer
245 views

Should I be returning promises from any function that uses them?

Promises is a fairly new pattern for me, so I'm still building my intuition for them. I recently came across a case where some code in an adapter-like bit of code was once synchronous, and then ...
-1
votes
1answer
163 views

Has anyone collated a comprehensive list of all the prototype-programming style javascript work? [closed]

I'm looking for a comprehensive (or as close as possible) list of all the prototype-programming style javascript work done to date. Does anyone know of such a list somewhere, or have the knowledge to ...
0
votes
3answers
371 views

Which is more readable: early returns, or conditionals? [duplicate]

I’m writing an asynchronous, Promise-returning function. In the processing I test some conditions, and if the conditions pass, the promise should be fulfilled (resolved), but if one fails, then the ...
-4
votes
2answers
3k views

Reliable device/browser/OS detection [closed]

Is there some reliable way to detect device/browser/OS of web page visitors except using the user agent string? This is not for rendering/functionality of the web page/application, but only for ...
-3
votes
1answer
94 views

Is there a best practice for naming class selectors for identification alone

Is there a best practice for naming class selectors for identification alone? For example, for defining a single amount field with action button, we end up creating several div containers and div ...
3
votes
1answer
181 views

How to name two functions that could be named the same?

I have a node app with a queue for processing jobs in the background. I have a file that exports a function which when run, creates a job in my queue. In that file, I also have the handler for this ...
31
votes
8answers
15k views

Does comparing equality of float numbers mislead junior developers even if no rounding error occurs in my case?

For example, I want to show a list of buttons from 0,0.5,... 5, which jumps for each 0.5. I use a for loop to do that, and have different color at button STANDARD_LINE: var MAX=5.0; var DIFF=0.5 var ...
0
votes
1answer
103 views

How to statically check you didn't forget to await for an async function

A common bug in JavaScript is to forget the await keyword when calling an async function. Of course you don't always want to await, sometimes you really want to get a promise. And of course you can't ...
5
votes
1answer
283 views

How should Rails be set up with an SPA client like Aurelia?

Let's suppose I have a backend with API-only Rails. There is also a Javascript single-page application (Aurelia, but could be something else) talking to this API. Should I keep these together, in the ...
0
votes
1answer
48 views

Performant way for archiving image files in NodeJS on each user requests

Scenario: Images are uploaded to the server once in a while. Users send an API request for downloading all of those images that were uploaded to the server (Images reside in the server itself). ...
0
votes
0answers
420 views

What is the cleanest way to model my domain in JavaScript?

I am building an SPA. It will use WebGL, Canvas and SVG for certain components, and html for rendering views. I have a messaging system setup to define messages coming from a server, which will get ...
3
votes
3answers
799 views

REST Api - Check if Action is allowed for entity

I'm asking this question for a colleague since he doesn't have enough reputation to post images in a question During our normal development we found a deficit in our REST Api. We display entities in ...
0
votes
1answer
68 views

What types of operations should go into Node.js as opposed to client side javascript functions

I am building a web app with a lot of different API calls: our own proprietary REST API, third-party library API calls, etc. All of these calls either retrieve data, update data, delete data, or ...
8
votes
2answers
3k views

Should the ternary operator be used outside of assignment statements?

Edit This isn't a question of whether or not the ternary operator is harmful. It's about whether or not there's a consensus about whether or not it should be used outside of assignment statements. /...
2
votes
1answer
750 views

Authenticate Joomla user from an external app based on Node.js, Javascript and MongoDB

I have an iOS App which currently pulls in all the data from the MongoDB using a Node.js server. Currently my API / my node server handles all the data manipulation the iOS app/Swift only displays the ...
4
votes
1answer
1k views

Python and JavaScript integration for offline use

I'm a first timer here so let me know if I should post this question in a different forum! I have a python program that takes in user input but is only useful when you're offline, I wanted to make ...
10
votes
1answer
519 views

Why most anonymous functions can't be JIT compiled and will never be optimized?

I just read https://techfindings.one/archives/2652 about functional programming and came accross this: anonymous functions can often not be JIT compiled and will never be optimized Can someone ...
2
votes
2answers
505 views

Polymorphism based on number of arguments?

I've heard that changing a function's behaviour based on argument type is called ad hoc polymorphism: program Adhoc; function Add(x, y : Integer) : Integer; begin Add := x + y end; function Add(...
0
votes
1answer
221 views

When to use stubs

I'm trying to get into TDD, and a lot of examples sugests that we should use stubs to make our code more flexible. If I'm using javascript (for example) then why should I use stubs, since methods and ...
1
vote
1answer
1k views

Web API & MVC Website - IdentityServer4

I am having trouble understanding the purpose of everything I am trying to do here. I have web api, mvc, and angular2 project linked by authentication provided by identityserver4 As in, why would I ...
7
votes
4answers
2k views

Clean, Modular Code vs MV* Frameworks [closed]

I've been hearing a lot about the "new" MV* frameworks. I've tinkered with KnockoutJS (I created an invoicing application), but I much prefer to write clean, modular code in raw JavaScript - ...
2
votes
0answers
129 views

Is there an accepted Coding Style for multiple ES6 Arrow Functions?

I'm starting to use ES6 arrow functions more, but haven't found a coding style that I like, especially when chaining them together. e.g., Eric Elliott gives this code: mix = (...fns) => x => ...
-4
votes
1answer
7k views

Using forEach on empty array [duplicate]

I have a dynamic array that can often be empty, and I need to iterate over all its elements. So far I have such code: array.forEach(function(item, index) { //stuff here }); It works fine of ...
24
votes
1answer
3k views

Module Requiring vs Dependency Injection in Javascript

These days a question popped out in my mind: Does the way we Javascript go against almost everything that is considered a good practice in traditional Software Development? I have a series of ...
6
votes
4answers
22k views

What is the real difference between a minified and uncompressed file? What are the benefits of each?

I often see something like "uncompressed for development / minified for production" when reading blogs or downloading frameworks. What is the real difference between the two, and if minified is "good ...
0
votes
1answer
132 views

How to plan unit-test design/structure for Javascript?

In opening I would like to say; I'm pretty new for programing. I'm working with JS for a year. Using Sencha's ExtJS and usign Bryntum's Siesta test tool for unit and integration(ui) tests. Right now ...
1
vote
0answers
46 views

Exporting functions usable by both client-side and server-side

So this isn't a question on how to do it, but more of a clarification on how it works. I'm using Vue and I'm creating a file that's usable by on both the client side and the server side (logic should ...
-1
votes
1answer
308 views

How to extract SSML parsing code of espeak to implement SSML parsing at SpeechSynthesisUtterance?

eSpeak implements SSML parsing. SpeechSynthesisUtterance, at least as implemented at *nix, does not parse SSML input at Chromium or Firefox browsers. How to identify and extract the relevant portions ...
2
votes
1answer
727 views

Animations and React — is it bad practice to mix them?

I have been in arguments with programmers that mixing elements with animations and react is very bad practice, and that all animations should be in a style sheet because that is something ...
1
vote
3answers
1k views

How to handle parallel requests, different response time and atomicity of transactions

I have a table of data and I can create , update and delete rows. I have apis to do these operations. The following steps happen I create a row and send a create request to server. I update some ...
0
votes
1answer
81 views

WebApp Design: Better way of updating information in a DOM element

Background: I was working on a personal project to create an Task Checklist Web App. I worked on the code with vanilla golang and javascript. It is a very simple app with limited capability. I've used ...
91
votes
6answers
21k views

Does immutability hurt performance in JavaScript?

There seems to be a recent trend in JavaScript towards treating data structures as immutable. For example, if you need to change a single property of an object, better to just create a whole new ...
4
votes
3answers
1k views

Starting an HTML canvas game with no graphics skills

I want to do some hobby game development, but I have some unfortunate handicaps that have me stuck in indecision; I have no artistic talent, and I also have no experience with 3D graphics. But this ...
1
vote
1answer
96 views

What is the best way to store message threads?

I'm integrating a messaging feature into an application written in Javascript and would like to know which is the preferred data structure of storing messages. The two structures I can think of so ...
47
votes
10answers
46k views

Why Should I Avoid Inline Scripting?

A knowledgeable friend recently looked at a website I helped launch, and commented something like "very cool site, shame about the inline scripting in the source code". I'm definitely in a position ...
8
votes
4answers
7k views

How to avoid javascript becoming spaghetti code?

I've done quite a lot of javascript over the years and I'm using a more object-oriented approach, specifically with the module pattern. Which kind of approach do you do use to avoid a bigger code-base ...
0
votes
1answer
736 views

Difference between JavaScript self-executing function and constructor function in private methods

I know this has been asked many times before, but I still don't quite understand what the difference is between the following: var Foo = function (){ //1 this.a = ""; this.b = ""; var ...