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.

0
votes
0answers
13 views

Correct way to call a URL on button click [on hold]

So, I wrote a Java servlet to get a zip file from the server which works fine when I use a web browser to test it. My URL looks like the following : https://myserver.com/Download/FileServlet?...
0
votes
3answers
102 views

Code design: introduce new method vs add optional parameter to existing method

In JavaScript (ES6), I can have optional function parameter with default value. So to add a new behavior to the existing code base, I could either introduce new method(s) or extend the existing method ...
1
vote
1answer
133 views

Download file stream as it's being generated

Scenario We are building a UI that allows users to query our data in bulk. The return format is CSV and there is a decent amount of processing that needs to happen, so this processing processing is ...
0
votes
1answer
27 views

Handling different error types from diffierent libraries with express

Most of the express error handling documentation and tutorials I've read suggest using Express middleware to throw errors up to, and to handle the errors there. eg. From the Express documentation: ...
19
votes
4answers
16k views

Why would I use Angular?

From the basic Angular tutorial, it seems like all it does is fetch some JSON from an API and display it. Also, there's its double binding magic. But why would I use it instead of a backend solution (...
-1
votes
0answers
50 views

How to avoid circular references in JavaScript?

I have two classes. A Bot class and a Client class. Heres a relevant section of the Bot class. class Bot { constructor(client) { this.client = client; this.client.on(ChatEvent....
0
votes
1answer
24 views

How to define Composition Roots for libraries (Javascript/inversify)

I'm building a console app (A), which depends on library B. Library B further depends on library C. I am building all 3 entities. Most of the development completed so far has been done using a ...
-4
votes
0answers
66 views

Is this the correct design? [closed]

I'm new to software design and I'm trying to write a JS application that some people might find simple but will be the most I've dealt with JS. I hope this forum is the right place where to ask my ...
0
votes
1answer
34 views

Potential Solutions to loading Javascript classes unknown at run time

I'm looking for some advice or potential options for loading javascript files in real time long after the DOM has fully loaded. Those javascript files need to be sent over a WebSocket connection, and ...
40
votes
4answers
42k views

Why do C# developers newline opening brackets? [closed]

I've spent most of the last several years working mainly with C# and SQL. Every programmer I've worked with over that time was in the habit of placing the opening brace of a function or control flow ...
0
votes
1answer
87 views

How to avoid code duplication caused by javascript dict access?

I have two functions that group a list of dicts according to the value of a certain key. Here's how my array looks: const sections = [ { file_id: '1', heading_level: 4, readme_file_name:...
0
votes
2answers
5k views

How deeply can a JSON object be nested?

I was watching a video on a website that said json objects can be nested deeply. How far can a JSON object be nested before it will create an error?
-1
votes
1answer
46 views

NodeJS SocketIO Multiplayer Multiple Game Room Management

I am making a multiplayer card game and am using NodeJS as my server with SocketIO. My question is how should I be managing multiple game rooms (say an n number of game rooms) ? Currently I have it ...
0
votes
1answer
52 views

How to design a system that can operate and replay its functions call stack?

I am writing a processor for the Citation Style Language (CSL) in JavaScript. Before I explain what my problem is, I must give some context first: CSL is an XML specification for describing how to ...
-2
votes
0answers
34 views

How to Evaluate the Best Tech for a Project [duplicate]

I hope this question isn't too subjective for SE, but I feel that a precise answer or approach can be given. First off, I have spent some time researching this issue but I am posting the question ...
41
votes
7answers
11k views

Why not embed styles/scripts in HTML instead of linking?

We concatenate CSS and JavaScript files to reduce the number of HTTP requests, which improves performance. The result is HTML like this: <link rel="stylesheet" href="all-my-css-0fn392nf.min.css"&...
4
votes
2answers
209 views

How to test database dependent functionalities?

I have written this function which checks if a user already exists in the application: async function ValidateUserExists(username, email){ if(!username || !email) throw new Error('Invalid number ...
1
vote
1answer
59 views

What is a message in relation to javascript's message queue in its event loop?

I'm learning about javascript's event loop, however I'm not understanding what a message is? The resources I find mention how the callback associated with events get added to the message queue, but ...
7
votes
6answers
4k views

Why do programming languages not let you use a try block without a catch block? [closed]

Why do languages demand catch blocks when they aren't needed? The compiler or parser complains with this code: try { const utils = require("applicationutils"); } But it is OK with this code: ...
1
vote
1answer
42 views

Form validation or model based verification on client side

I'm actually wondering what are the pros and cons of these two ways to handle client side validations / verifications. Let's imagine an application where there is a contact form that needs these ...
2
votes
7answers
947 views

Why don't languages use the words “and” and “or” instead of “&&” and “||”?

When I was a beginner it took a while to learn the language syntax and the idea that languages couldn't improve after they were invented. But now we're seeing new language features added every year ...
9
votes
3answers
11k views

Is it bad practice to use hyphens in JSON keys?

I see a lot of questions revolving around accessing JSON keys that use hyphens (kebab-case), but now I find myself wondering should I just stick to camelCase or snake_case in my keys. I know hyphens ...
1
vote
1answer
55 views

Is it normal approch get all items after post new item?

Problem description: Parent view displays a list of items. This view has button add a new item to list wich open modal for creating a new item. Two approaches how to do that: 1) POST Request -> ...
1
vote
1answer
244 views

When writing tests for a WordPress plugin, should i run them inside WordPress or in a normal browser?

I have started using BDD for a WordPress plugin i'm working on and i'm rewriting the js codebase to do tests. I've encountered a few problems but i'm going steady now, i was wondering if i had the ...
23
votes
6answers
17k views

Are UML class diagrams adequate to design JavaScript systems?

Given that UML is oriented towards a more classic approach to object orientation, is it still usable in a reliable way to design JavaScript systems? One specific problem that I can see is that class ...
2
votes
1answer
128 views

DDD / Onion architecture in JavaScript

One reason I like .NET is because the 'solutions' and 'projects' lends themselves to good architecture. Good architecture makes it easy to follow the happy path of Domain-Driven Design. I've fallen ...
0
votes
0answers
54 views

Handling user permissions in front-end

I'm building an API that will be used by the front-end in React and I'm not quite sure how I should send the permissions of each user based on their roles. Some fields can only be edited in some ...
0
votes
1answer
63 views

JS Higher Order Function is even necessary in this scenario?

In Javascript, I have seen a code like: const getSomeMapper = (param1, param2, param3) (param4, param5, param6) => { // uses all these params and returns a promise } interface ...
0
votes
0answers
65 views

Should modules strive to export only one thing?

Ideally, functions should do one thing well, and only one thing. Does the same thing apply to what a module should export? Of course, modules aren't always the same thing as functions, but they often ...
3
votes
1answer
740 views

What is a good method of storing test data for development and unit testing with angularjs and jasmine?

What is a good method of storing JSON data/objects for development and unit testing with angular and jasmine? I have seen some ways of accomplishing this. However, since I am new to unit testing with ...
-2
votes
1answer
130 views

Is there a way to recreate the code behind the for loop?

My question is, how would I go about making a function that serves the same purpose of the for loop, without using any loop method. function fl (initial, condition, iterator, code){ i = initial; ...
8
votes
1answer
6k views

Node.js app private modules. Where to put them?

The situation would be: I develop 2 projects in my Node.js development environment, P1 and P2. P1 required the development of two simple modules, mod1 and mod2, which are stored in P1/lib. Each one ...
0
votes
1answer
56 views

Cross-domain data binding

I've been developing several front-end web-applications recently that bind against a database using a RESTful CRUD api. I've noticed a massive amount of boilerplate code going into defining the API. ...
1
vote
1answer
1k views

Angular2: Service architecture + error handling

I need support for Angular2 service architectures. I am quite familiar with Angular2 but I don't see the best way to implement services, error handling and their connection with the components. I'm ...
0
votes
0answers
55 views

Why does Babel convert async/await to generator functions rather than promises?

It's a bit of a moot point now that async/await is supported by all major, modern JavaScript engines, but I've always wondered why Babel converts async functions to generator functions rather than to ...
0
votes
2answers
118 views

Card game with unique abilities - how do i implement this

I am making a card game, it is similar to Bang. You have a boss, which has some HP and you are getting cards with abilities, HP,DMG, etc. I want to make it as a .io game or maybe just a web ...
0
votes
0answers
28 views

Why does Vue.js rename / move all the internal data elements?

I'm following the code from Vue.js in Action, Chapter 3. (much deleted for brevity...) var webstore = new Vue({ el: '#app', data: { sitename: "Vue.js Pet Depot", showProduct: true, ...
1
vote
2answers
714 views

ModelState Validation vs JQuery vs Remote

I was stuck with some validations for quite a while. I have been thoroughly searching the internet to find ways to apply the validations I require. I came across many methods for validations even ...
0
votes
1answer
58 views

How to organize work with a few projects with shared codebase?

We develop two projects (and more in future) with JS, Vue.js, using npm, and we store each project in its own git-repository. We want to place common components (buttons, page-parts and page ...
1
vote
1answer
1k views

Efficient development process for Golang (or any backend) and JavaScript?

I am developing a web application. The frontend is a mix between JavaScript and server-side generated html. The backend is written in Golang. Might not be very important, but if somebody made a ...
22
votes
2answers
12k views

Confusion about dual license (MIT/GPL) javascript for use on my website

I've read all of the posts I can find on this and I'm still not sure of the answer. I'd like to use a jQuery plugin on my website that is dual licensed under MIT and GPL. Does the dual license mean ...
0
votes
1answer
112 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
1answer
404 views

Angular template variable reference [closed]

Here is a weird problem in Angular: <input #pin1 type="password"> <p>You entered: {{pin1.value}}</p> If you type something in <input>, the <p>'s content will not change ...
22
votes
4answers
34k views

What is the need of Odata when I have JSON?

I am trying to understand the point of Odata and when it would make sense. Right now how I work is I use ASP.NET and MVC/WebApi controller to serialize/deserialize objects into JSON and have ...
0
votes
1answer
79 views

Is JavaScript added and executed in rendering or parsing?

AFAIK, each web page is created in a two stage process: Parsing and rendering. In parsing, markup (Say HTML) is taken as is, or created from a server-side programming language like PHP, In the ...
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 ...
1
vote
1answer
49 views

Dynamic execution of Template Literals using a Map

I have a system that is generating internal events for objects. I am extending their debugger to display a human-readable version of the events sent to the debugger. For instance, the system will ...
0
votes
1answer
243 views

Organizing reducers in Redux

I will use the following popular todo list example for demonstration. Let's say I wanted to create a very basic todo list with this structure as the app state: { todos: { todoKey1: { ...
6
votes
1answer
717 views

Order and filter Server-Sent-Events in angular.js eventsource

I have a Client in AngularJS where I consume multiple SSE (Server-Sent-Events) in Java from the Server Side (there are multiple endpoints in different web servers in the backend). Diagram link I ...
2
votes
1answer
792 views

Collecting user input to use as query with API

I'm attempting to collect the user's input and execute a search using an API. At this point, I can use the API (ebay search) by typing keywords into the html document- but I want the user to be able ...