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
2 votes
1 answer
1k views

Many small files vs fewer larger files: impact on bundle size and build time

I've been a relentless proponent of small files. I prefer one function export per file, functions with everything-in-one-view, and breaking up UI components as much as sensible (which is why I love ...
Faust's user avatar
  • 139
0 votes
2 answers
148 views

What is the best practice for incorporating asynchronous code in this case?

Context: I'm building a popup widget. The html and css files are stored in S3. I need to get those files asynchronously and then continue with the rest of the logic. In the code below, I'm getting ...
EnterPassword's user avatar
9 votes
1 answer
3k views

How & Should we use Clean Architecture in Front-end?

Just a little explanation: "I'm used to be a solo front-end developer in my company and using default folder-structure and way of coding which vue-cli provided, it is good for a solo developer and ...
SeyyedKhandon's user avatar
3 votes
3 answers
676 views

Read large JSON file and return a subset for map

To some extent, this is a wide question, because I do not know in which direction I should move. I am using Polymaps to show markers on a map. The markers are static but the visualization depends on ...
Whir's user avatar
  • 141
0 votes
0 answers
229 views

Should I create Thumbnail of video in Web App (client-side) or Lambda/Server-side?

I am trying to create a thumbnail from a video that I'll be uploading to my Web App(React). And then I'll upload that video to AWS S3, and thumbnail(image) to S3 as well. I wanted to know where ...
Tauqeer Hassan's user avatar
5 votes
3 answers
529 views

How to manage chaotic code explosion in React application

So we decided to redo UI of our web application in React. Six months down the lane and we have a complete mess of components and reducers and thunks and actions and god knows what not. We have ...
lahory's user avatar
  • 315
2 votes
0 answers
231 views

React Hooks: using state in useEffect without depending on it

I have run into a situation in React where I want to run a function F in a useEffect hook whenever a value V1 from the store changes. F uses another value from the store V2. I only want to run F when ...
Ace's user avatar
  • 597
0 votes
2 answers
159 views

Should we check if the primary key exists if rendering a collection fetched from database?

I have got an argument with my colleagues about this. IMO It's common practice that you don't need to check if an id exists or not before rendering it. So here's an example. This is what my ...
Mak Suriya Jacobsen's user avatar
1 vote
2 answers
590 views

How to refactor duplicated functions with only one difference in parameter list

I've got 2 near-identical functions (NodeJS). One of them queries DB for shop information by its phone number, while the other one queries by its id. I'd like to know if there's a clean way to merge ...
Zolbayar's user avatar
  • 139
0 votes
2 answers
275 views

Why don't people usually use asserts throughout their application?

I usually do Javascript and I like putting console.assert liberally in my application. It throws an error if the first argument is falsey. E.g.: console.assert(price > 0, 'Price isn\'t above 0') ...
Leo Jiang's user avatar
  • 117
2 votes
4 answers
795 views

When a function can take a single item or multiple, is it better to have more than one function or just one function that takes arrays?

Consider something like.... (Pseudocode Javascript like) var capitalizeWord: function(word){ word.toAllCaps(); } What if now I need to do multiple words, but still sometimes only do one still. ...
Carson's user avatar
  • 131
2 votes
1 answer
574 views

Should Javascript events always emit to window?

I'm going to start with the opposite of my question: why should events emit only to a specific context when your code is supposed to be easy to interact with? In the JS world, you can emit events ...
Daniel M's user avatar
0 votes
1 answer
56 views

When should javascript files be loaded

I am using a great deal of jquery. I have several "sub-pages" that are loaded into a main div by a menu click. Each of those sub pages has an associated javascript file. I have been loading the ...
Dave Davis's user avatar
-2 votes
2 answers
456 views

Alternative to RLE for short, infrequent runs

I have 3 number arrays that I need to encode into a URL through query parameters. Example: http://localhost:3000/?r=133223333302302040&y=10000000000000000000&b=13333332002100122331 This is a ...
Simon's user avatar
  • 127
4 votes
1 answer
255 views

VueJs - composing components for large scale projects

I started getting into VueJs and Vuex development and I'm looking for a "mainstream" architecture for large scale projects. I think the question doesn't depend on whether you take a ready to use UI ...
Question3r's user avatar
9 votes
2 answers
415 views

Jumpy Code with Descriptive Function Names

I'm currently building out some functionality on a page. When writing JS I've been making a set of smaller functions like FindCarouselLocations(elem), GetImagesFromLibrary(url), and BuildCarousels(...
KGlasier's user avatar
  • 219
1 vote
3 answers
4k views

Good practice for JavaScript (ES6) data objects

I see very often to pass around unnamed data objects in JavaScript, e.g. { a: 1, b: 2}. Is it a good practice or is better to make a simple data class for that like in other languages: class ...
xmedeko's user avatar
  • 186
173 votes
4 answers
35k views

Why is JavaScript not compiled to bytecode before sending over the network?

You'd often see that JavaScript is actually being transported over the web with all the useless stuff that doesn't need to be there -- Comments, particularly those containing licenses, indentations ('\...
zombiesauce's user avatar
  • 1,439
1 vote
1 answer
199 views

maintain server business logic for multiple version of offline client

I have an offline application and the data is 2-way synchronised between server and the app using pouchdb-couchdb. One requirement is both the server and the app must able to mutate the application ...
kingwei's user avatar
  • 147
5 votes
2 answers
3k views

How do JavaScript engines convert async/await to promises under the hood?

I'm curious how the async/await syntax is converted to Promises. Maybe I'm just not thinking about it properly, but I don't know how this code would be converted to a Promise: async function myFunc(...
dx_over_dt's user avatar
1 vote
1 answer
59 views

Does it make sense to use reflection or to hard-code controller parameter names in JavaScript?

So I have made a pull request to change this code: //Controller: ... [HttpPost] public ActionResult Unauthorize(int userID, int permissionID) { ...
Sarov's user avatar
  • 403
-1 votes
1 answer
48 views

Can Ionic apps be easily ported as a Web Application?

I am newbie to angular and Ionic world and trying to figure out the right stack to get started with my requirement to develop a hybrid mobile app. I understand that Ionic is a wrapper around other ...
Vishal Kumar's user avatar
-3 votes
2 answers
1k views

How can I calculate the radius of an arc given by a series of points

Given a series of points, I need to assert that the plotted points form an arc (with a certain level of confidence), and I need to approximate the radius of the arc. For example, the following points ...
Yanick Rochon's user avatar
4 votes
1 answer
3k views

Form validation code shared in the frontend and backend API?

I have a legacy Java monolithic web application. My goal is to use React on the frontend, keep Java on the backend and add an API for the frontend to use. My question is how can I write the data ...
Dan's user avatar
  • 41
-2 votes
1 answer
979 views

How to make code runnable on open source code editors like Ace Editor?

For my computer science uni project I'm required to build a web application with an integrated code editor. I believe I can just integrate open source editors like Ace Editor. However, I feel ...
Sonjeet Paul's user avatar
0 votes
1 answer
58 views

Documenting JavaScript types received from API in VueJS

I'm using VueJS and have data coming as json via web API. The API is strongly typed, but in my Vue component, I don't have a good way of knowing what the types being passed are. Given the following: ...
jleach's user avatar
  • 2,682
0 votes
2 answers
238 views

Code style to keep track of nested objects and data types?

In untyped languages (Python, Javascript specifically) find myself making a lot of bugs / wasting a lot of time because I forget what's in the objects I'm passing around. For example, I forget things ...
Jess's user avatar
  • 173
2 votes
1 answer
98 views

ReactJS - lift state to main container or export a helper?

I'm using ReactJS (React Hooks, specifically) to build an application. Part of that application involves account creation, sign-in, and authentication. I only recently finished the sign-in feature, ...
IceMetalPunk's user avatar
3 votes
3 answers
3k views

Node.js error handling through each layer

I am looking for a way to handle errors in a Node.js application without getting lots of log entries for the same error event, one from each each affected layer. This might actually apply to any ...
spin_round_22's user avatar
1 vote
1 answer
95 views

Transpiling in npm modules

While recently creating a module for shared functionality between our projects I stumbled upon this question. Should the module be occupied with transpilation of code to older browsers that our ...
Leon's user avatar
  • 197
5 votes
1 answer
2k views

Domain classes in DDD structure in React apps?

I'm building an Electron app using React. I'm coming from the C# and WPF world and I'm wondering, where should my domain classes go? I understand the concept of components, but what about a class with ...
Ish Thomas's user avatar
0 votes
0 answers
60 views

Ist good practice adding Converter Between api and client

I just want to curious about adding a converter is a good practice or not. I have multiple API and I always convert API return fields to my client fields. Like=> function ConvertFromAPI(apidata){ ...
Loran's user avatar
  • 101
3 votes
2 answers
623 views

What is an example, in Javascript, of the difference between Abstraction and Indirection?

I thought I understood what abstraction meant - refactoring code so that it applies to more general use cases. However I have recently learned that some types of abstraction may actually be ...
drenl's user avatar
  • 167
2 votes
2 answers
2k views

How can I emulate Signals and Slots found in Qt, to Javascript / Typescript Classes?

Ive brought this up with other developers, and they say while there is no obvious way forward, it seems that they all have an idea of how to go about it. Is there any way I can implement signals and ...
Anon's user avatar
  • 3,603
4 votes
4 answers
2k views

Best practice in synchronized form data validations (Web apps - Client-Server)

Here we go again with topic what was asked many times all over internet, but I not found any good enough answer: What are best practices in making client and server side validations synced? I was ...
Baterka's user avatar
  • 165
3 votes
0 answers
190 views

data transfer objects between abstraction layers

I want to create an Express REST API and want to try following the clean architecture ideas. I was reading about it but didn't get the idea of the communication between the abstraction layers. Let's ...
Question3r's user avatar
0 votes
1 answer
2k views

Passing javascript function vs use imports in Svelte or React component

I wanted to use some function from javascript module in one of my component. Should I pass it in props when making the component or should I just use Imports in component itself to get the javascript ...
hatellla's user avatar
  • 171
0 votes
0 answers
44 views

Methods for storing data pre-registration in a web app

I have a web app - it's more complicated than a todo list but for simplicity sake let us assume it is a todo list. The user has the choice to sign up and create an account thus allowing them to store ...
William's user avatar
  • 109
0 votes
1 answer
32 views

Contemplating about API design of a typescript/nodejs library for querying a remote storage service

I am working on a Typescript library (to be used by many users within my org, possibly open-sourced) which provides access to some remote storage. I am contemplating between several variants for the ...
Itay's user avatar
  • 117
2 votes
1 answer
2k views

Is this the right way to handle errors using the fetch api?

I am using the fetch api in my handleSubmit function in a React component to post data like this: handleSubmit(event) { event.preventDefault(); var error = false; var { username, password } = this....
Antonio Pavicevac-Ortiz's user avatar
1 vote
2 answers
1k views

Notify thousands of clients with websockets, are there any caveats?

I'm building a web app, where users can create locations, which are displayed on a map. Also, users can click on the map objects in order to get to a place details page where further interactions ...
Getter Jetter's user avatar
2 votes
3 answers
1k views

Any reason to not use a triple not?

If logical not ! will switch a boolean value from false to true or true to false and a double not !! will cast a value from one primitive type to boolean is there any reason one can not use a logical ...
1.21 gigawatts's user avatar
9 votes
2 answers
4k views

Is `this` in JavaScript an example of dynamic scoping?

Variables in JavaScript are lexically scoped. But, I wonder, is the this keyword, referring to the receiver of a method, an example of dynamic scoping. Or is this unrelated to the lexical/dynamic ...
user1283776's user avatar
0 votes
1 answer
694 views

Does it make sense to write one unit test and loop it through similar components?

I have a situation where I have different forms, each with 4 or 5 steps (components), and I decided to write one unit test per step. After doing it, I noticed they were very similar and I could just ...
sergioviniciuss's user avatar
2 votes
0 answers
324 views

Send push notifications from ActiveMQ

I am trying to figure out how to send push notifications back to the client in the following ActiveMQ scenario: I have a spring boot web application #1 deployed on tomcat on RHEL server. From the ...
Tan's user avatar
  • 151
3 votes
4 answers
659 views

Should one-line functions be avoided in jQuery/JavaScript?

So, I had a coworker complain about how I made the following code: ... var foo = getKendoDropdown(window.foo); var bar = getKendoDropdown(window.foo); var sna = getKendoDropdown(window.sna); var fu = ...
Sarov's user avatar
  • 403
0 votes
2 answers
167 views

Common header file for C++ and JavaScipt, redux

I've got a question closely related to this one. I'm cleaning up a colleague's mess, and I'm afraid that that means trying to work with a language -- JavaScript -- that I'm almost completely ignorant ...
BunsenH's user avatar
1 vote
3 answers
846 views

Classification of methods that are only accessible by a child class and its parent

I'm trying to document some of my JavaScript according to this JavaScript Documentation guide and came across member access (private, public, protected). I was wondering what the classification would ...
KGlasier's user avatar
  • 219
0 votes
1 answer
78 views

Interruptible parsers in Javascript

I’m trying to write a parser in JavaScript that is able to be interrupted by the fact that the entire input source is not available during the parse. When subsequent chunks of the input become ...
oorst's user avatar
  • 139
0 votes
2 answers
238 views

Temporal coupling vs. complex constructor

I'm working through a book on writing Single Page Applications in Vanilla Javascript. (I'm working on a project where I'm not allowed to use React or any other frameworks, so I'm trying to get better ...
samfrances's user avatar
  • 1,085

1
3 4
5
6 7
43