Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

2
votes
2answers
113 views

Better method to adding lots of options in a function

I have a JS function that takes JSON data and creates an HTML table. As my project developed, I needed one specific table to be created with a button - so I added an option to the function and an ...
1
vote
0answers
107 views

Design differences in Angular UI components and regular JS UI components [closed]

I'm an experienced JS developer and I've been involved in front-end development for multiple web applications. I've developed a couple of custom JS components to suit the project. I'm currently tasked ...
8
votes
3answers
531 views

Communication between decoupled components using events

We've got a Web App where we have a lot (>50) of little WebComponents that interact with each other. To keep everything decoupled, we have as a rule that no component can directly reference another. ...
6
votes
4answers
790 views

Best way to do Client side authorization for a single page JavaScript application?

I already have a solid back-end permissions authorization (ie. admin can perform an action, a normal user cannot perform an action). However, I'm wondering if there is a better way to do a frontend ...
0
votes
1answer
104 views

Serialized Object Representation in Javascript from PHP

Let's say I have a Widget object that I serialize and send back to the browser at a regular interval. This Widget object includes lots of different members (variables) and other objects along with ...
0
votes
1answer
46 views

Is creating near duplicate partial views solely for populating html elements with Ajax returns violating DRY?

Maybe anti-pattern is a better word for this question. I do not know, but I mean a violation of DRY. Id like to reuse a partial view, and I can, but that partial view has other things in it I don't ...
16
votes
4answers
1k views

Unable to solve mystery of functions in Javascript

I am trying to understand behind the curtain scenes of Javascript and kind of stuck in understanding the creation of built in objects, specially Object and Function and the relation between them. ...
0
votes
1answer
66 views

Ext JS: Designing a base class and override it

I'm trying to define a base class and override it's items on different inherited sub-classes. I'm following MVVM pattern to fetch records from backend. Created several stores and formulas within ...
0
votes
1answer
116 views

Architectural Problem in use of ToneJS with Vuex

I'm using the Tone.js library to build a (music) sequencer in Vue+Vuex, and have encountered this problem: Individual music tracks of the sequencer are created dynamically, so I'm storing objects ...
0
votes
1answer
98 views

What would be more efficient, move DOM elements or clone them?

I have this dilemma, I have to make a menu, the basic estructure is four to six main menu items and each one can have N level 2 menus and each sub menu can also have subs. I get from the server this ...
1
vote
0answers
113 views

Understanding transducers, why this is not a transducer

I'm currently learning functional programming and trying to learn a new concept : transducers. I'm actually getting the point of theory, like it's an advanced map/reduce that aims to provide better ...
3
votes
1answer
141 views

What is the standard method of handling errors in a NodeJS web app?

I am currently working on a web application as a learning project, which has a NodeJS backend and uses a MongoDB database; however, I believe my question is not specific to the technologies I am using....
0
votes
2answers
86 views

How should I dynamically retrieve data depending on the size of the user's browser window?

I'm developing a chat module for my employer, and one of the requirements is that I "get enough backlog to fill the screen" when opening the room, instead of always limiting it to a specific number ...
-4
votes
1answer
89 views

What is the truh concerning pasting data into a browser? [closed]

I am hearing a ton of different info. I just found this in a site The 'paste' operation in the context menu or button press is not possible. It is not possible because of a browser security ...
0
votes
2answers
55 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, ...
1
vote
0answers
118 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
882 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 ...
3
votes
1answer
56 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 ...
0
votes
1answer
2k views

element.style.setProperty(property, value) vs element.style.property = value [closed]

I was wondering if I should use element.style.setProperty(property, value) or element.style.property = value. I am very much tempted to start using element.style.setProperty(property, value). But in ...
0
votes
1answer
1k views

Should I generate GUID/UUID on client or server?

I want to generate a GUID/UUID for my web app to use but I'm not sure if I should generate it on the client or server or what should be the preference. Basically, I'm working on a web app similar to ...
1
vote
2answers
805 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 ...
0
votes
0answers
16 views

How should Selection selectfinish/selectend event be implemented?

I'm looking to do something whenever a user finishes making a selection —essentially, on the first mouseup event after every selectstart event, I think— on the page. I want to take that selection and ...
2
votes
1answer
174 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 ...
0
votes
0answers
113 views

MVC and ashx files

We have a single page app which creates all Gui with JavaScript/css. No server side generated gui from aspx files etc. the JavaScript typically loads json data from the server using xmlhttprequest ...
1
vote
0answers
102 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 ...
0
votes
0answers
41 views

Patterns for pre-emptive background work scheduling

Here is problem I hope the community can help me analyze: I want to execute a set of jobs with one background worker (or several). Whenever a job is done, a message is fired, and a listener on the ...
0
votes
3answers
220 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 ...
0
votes
0answers
148 views

WYSIWYG text editor design: replace all spaces with spans or master manipulation of nodes?

The goal of this contenteditable div editor is to be able to: double-click on words to add a span around it and further functions highlight range of text (more than 1 word) to do the same as above ...
0
votes
1answer
501 views

Is it okay to use var on purpose in ES6, as opposed to let?

I was really glad that ES6 introduced the let keyword for defining variables. var scoping rules can lead to all kinds of issues, especially when working with loops and event handlers. Even when ...
3
votes
1answer
172 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 ...
-4
votes
2answers
931 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 ...
0
votes
1answer
88 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 ...
30
votes
8answers
13k 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 ...
-3
votes
1answer
86 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 ...
0
votes
1answer
45 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). ...
1
vote
1answer
244 views

Why bother with server-side form submissions in a SPA?

I am all in favour of progressive enhancement and using server-side rendering when fetching a URL. The age-old discussion gives several advantages, such as improved load time, SEO crawling and ...
0
votes
0answers
256 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 ...
2
votes
4answers
325 views

JavaScript only validation on AJAX form submit

I've been mulling this question over for a few days in my head and I can't come to a solid answer. We understand that client side validation for forms is not enough, because you can easily turn ...
3
votes
3answers
534 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 ...
6
votes
1answer
1k views

Why use `const foo = () => {}` instead of `function foo() {}`

For example, in this Redux video, the instructor always uses syntax like const counter = (state=0, action) => { ... function body here } where I would just use the "traditional" function ...
3
votes
1answer
722 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 ...
8
votes
1answer
405 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
399 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
160 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 ...
2
votes
0answers
120 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 => ...
0
votes
0answers
35 views

How can I test an Express Controller that talks to 3rd party integrations?

I have a simple express server. There is a route that accepts both a NPS score and an email in it's req.params. Here: app.put('/api/nps/:score/:email', npsController.sendIntercomNPS) The actual ...
-4
votes
1answer
3k 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 ...
0
votes
1answer
99 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
40 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
197 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 ...