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
1answer
148 views

Web Components/Redux with .NET Core MVC viable?

I'm currenty building several new themes using NopCommerce, a .NET e-commerce platform using the MVC architecture. NopCommerce exposes a lot of services to you for communicating with the db, and is ...
0
votes
0answers
46 views

Best way to trigger javascript error to go to catch block

I have a couple of doubts regarding the quality of my code. I'm working on a helper function (for KoaJS) where I'm validating a Firebase ID token. If it is valid, I return the decoded token; otherwise ...
34
votes
9answers
9k views

Is it good practice to echo PHP code into inline JS?

I'm new to PHP and JS and I'm currently working on a gym management web app for our project in school. I'm adding a bit of QR functionality that sees if the user is eligible to enter the gym or not by ...
2
votes
3answers
210 views

White-Box vs Black-Box

I need some clarification on White-Box vs Black-Box testing. Is it correct that: White-box testing is testing your code that you are familiar with? Black-box testing is testing someone else's code you ...
0
votes
1answer
51 views

Sending multiple calls from angular application

I am working in Angular project which is connected to REST API. Here we have an endpoint to create and update room types. POST endpoint for create and PUT endpoint for update exiting room types. Both ...
1
vote
0answers
44 views

Securing Arbitrary Code

I need to run arbitrary code snippets in Python and Javascript on a server. It cannot be run in the browser. I'm thinking of sandboxing the code in an AWS Lambda serveless function. However, I'm ...
0
votes
5answers
1k views

What should the result be of a failing parseInt function?

When providing JavaScript's parseInt with a non-parsable string it returns NaN. I'm trying to understand the reasons for designing a parsing function this way. When I write a parsing function I ...
-2
votes
1answer
55 views

Authentication solution for custom PHP-based API

Here is description of my app I'm working on. On the client-side (index.html) a user can interact with a data. When he needs to call a server operation for example reading or writing a file on the ...
1
vote
0answers
45 views

advice for web communication protocol for "streaming" multiple JSON objects to multiple clients

As a hobby / to learn I am building an app in JavaScript using Node.js where a component of it will take input from a client, send it to a server, and then broadcast it to other clients. For ...
4
votes
2answers
185 views

Arrays vs Maps for listing items that have a unique id

I've been finding that for a lot of code I've been writing recently, it naively might look like this: Array approach: const options = [ { id: 'red', label: 'Red', data: '#f00' ...
-1
votes
1answer
64 views

How to record the sequence of events effectively when there is a logical flow runs over various event notifications?

Let me explain what I mean there is a logical flow runs over various event notifications based on our web app, which is event-driven and it is quite common in my opinion. User clicks a button to ...
7
votes
1answer
1k views

Is it bad practice to require the same module in multiple files in Javascript?

Let’s say I have three files, all of which import a fairly large module. But I’ve divided them because they have different functions. Now each of the JavaScript files needs an initial statement like ...
2
votes
0answers
68 views

I'm trying to write something that will fill out an Australia Post Declaration Form [closed]

I've got basic proficiency in PHP, JavaScript, html, and SQL. I also use Postman little a bit. I hope a solution to my problem can be found within those skills, but I'm willing to learn a new language ...
0
votes
1answer
110 views

Would an mutable to immutable transpiler be possible?

I'm very new to writing immutable code. Would there be any fundamental issues trying to transpile arbitrary mutable code person.age = 20 into immutable code person = { ...person, age: 21 }? I am aware ...
-5
votes
3answers
730 views

How to unit test a public method that calls a private method [duplicate]

Here is a very basic example to illustrate my point class SomeClass { publicMethod1(param1, param2) { if (param1 === "some value") { // do stuff } else { ...
4
votes
1answer
148 views

Clean way to handle different exceptions in Javascript?

I'm Java developer and I'm now learning Javascript creating a personal project. I don't know how to handle different errors in Javascript in a clean way and I can't find a good solution on the web. I'...
0
votes
0answers
39 views

What are the ways to provide safe & reliable third-party ecommerce tracking to your users?

The project idea is the following: Build a website where you allow ecommerce brands and their affiliates to register to our site. Brands would list their products on our site that they wish to include ...
0
votes
1answer
58 views

Need help with React Shape building app architecture

I am trying to figure out how to build most scalable and maintainable architecture for my app. The app is just about choosing some shape and then editing it. More precisely, choosing some existing ...
0
votes
2answers
58 views

Setting custom callbacks in a Javascript applet?

I'm designing a 3D visualisation applet in Javascript. When used, a Canvas will be created and placed inside an HTML element on a webpage, specified by the developer who is implementing the applet. ...
3
votes
0answers
755 views

Setting width/height of unknown images for lazy loading

I have a site where users upload images & can all be viewed on a single page by other users. I want to lazy load images as the user scrolls instead of loading all initially. This is easy enough, ...
2
votes
3answers
175 views

Good ways to prevent client side logic duplication without HATEOAS?

I know HATEOAS can be a bit of a heated topic. Some people like it, some people don't. That is not what I want to discuss. What I want to discuss is what technology other than HATEOAS (or some form of ...
2
votes
2answers
163 views

Providing same API implemented in multiple languages

Our budding (currently internal) API deals with building information models, originates in our main application written in c++. There is a small implementation of it in C# for easy interop with other ...
0
votes
1answer
66 views

Best technique for sending multiple files in a single JSON post with Vue/javascript?

Using Vue/Electron to post to rails/Postgres backend. Is there a common design pattern/approach to posting multiple audio file objects BUT in a single post request? My current process (which works, ...
-2
votes
1answer
138 views

Should I repeat my code or use if statement?

A question from a friend: I have multiple usages for the same code, let's say a vertical HTML card. I change the title and a lot of data based on the react component. it feels unnecessary performance-...
2
votes
1answer
113 views

Exception handling with adapter design pattern in JavaScript

I am using an opencv.js Web Assembly build in the browser. The build comes with a JavaScript interface to call the WASM functions but it does not provide any memory management. For example every time ...
0
votes
1answer
62 views

Structuring a Compiler in a Dynamic Language (JavaScript)

For learning purposes, I'm trying to build a compiler in JavaScript for a tiny custom language and turn it into WASM. So far, I've got a lexer and parser, that turn my code into an AST, my question is ...
0
votes
0answers
113 views

Handle multiple buttons with different API IDs in a HTML table

Ok, so my scenario goes like this: I am building an API of financial transactions. Backend does not matter for this problem, the only thing is that the API has a route /users/:userid/transactions/:...
0
votes
2answers
120 views

Unit testing multiple features in one test

I'm writing a small utility class to create an abstraction for addEventListener (JavaScript/DOM) Let's say I have to test for these features: Single event target with a single event Multiple events ...
2
votes
1answer
169 views

Is it an antipattern to pass an object that stores the application state from one function to another?

The program is written in JavaScript. To give you a rough idea what I am thinking of: function State() { return { color: 'green', size: 100, // ... there are other properties here } } ...
-1
votes
1answer
307 views

What are downsides to opening local html files in the browser?

Let's say you have a scenario where you want to build a simple web stack (html/css/js) prototype to share with someone. I am a little unclear on whether or not I want/need to use a small web-server to ...
-3
votes
1answer
42 views

Testing a React component which receives a function as a prop

Suppose there's a root <App /> which houses multiple components, one of them being, say <SearchBox />. App component houses the app state (such as searchResults array) and iterates the ...
5
votes
1answer
462 views

Should published npm packages target ES5 syntax?

A bit of background: I've been using Webpack with babel-loader for a while and overall the experience has been hugely positive. Yesterday, I published an npm package of my own (to a private registry), ...
4
votes
3answers
536 views

Is this extensive usage of closure a known (anti-)pattern? And does it have a name?

I often use function closures for storing data (e.g. database URL), which doesn't change between function calls. Is this an (anti-)pattern? Does it have a name? While developing apps, which recieve ...
2
votes
2answers
228 views

How do modern JS engines terminate unresponsive scripts?

I'm trying to implement a safety feature that puts a timeout around a huge function call. Pretty simple, I thought, but it turned out much harder than expected; there's no built-ins for this in any of ...
16
votes
10answers
5k views

Are immutable objects important only in multi-threaded applications and if so, how are shared immutable objects useful?

I think the answer to the first part of my question is, "yes" -- no point in making objects immutable in a single-threaded application (or I guess in a multi-threaded application if that ...
1
vote
2answers
79 views

How can I cleanly set up debug logging in my javascript frontend?

I basically want to be able to "turn on debug logging" like you can do with many applications that run in a shell. The naive way of implementing it would be to insert a statement like this ...
0
votes
1answer
64 views

How to add event handlers to an object containing elements

I am new to JavaScript, I've done most of my coding in Python, and haven't found a clear answer to this question. If I have an object containing element ids and function parameters, and I want to add ...
2
votes
1answer
1k views

Digital Signature for PDF files through Web Application

We are developing a Web Application for manage dental clinics. The app can generate PDF files through the PHP backend (for example invoices, quotes etc.). Each of those PDF file needs to be digitally ...
-1
votes
1answer
196 views

Is async/await a good alternative for locks in JavaScript?

Yes, I know, the question title is a bit provocatory. But let me explain. I needed to execute a sequence of async tasks in JavaScript. They are async because I need them to be non-blocking, but I ...
23
votes
8answers
11k views

Can I use additional parameters in recursion problems?

Okay, I was being interviewed at a company and the interviewer asked me a recursion problem. It was an online interview, so, he had set up the problem statement and a function signature on CodeSandbox ...
3
votes
2answers
229 views

What is the rationale for making certain methods for data types static?

In C#, for instance, there are static methods for telling if a string is null or empty, finding an element in an array, clearing an array, etc. However there's an instance method for replacing ...
1
vote
1answer
86 views

How to manage 2 libraries that do mostly the same things in a project?

I am encountering a design problem on a new project. I have chosen the library Luxon (https://moment.github.io/luxon/) because I think it suits this project perfectly. Date-fns (https://date-fns.org/) ...
0
votes
0answers
73 views

Does v8 have nested stack frames?

In chapter 4 of the Zone JS primer the following is mentioned: So far, we have discussed how zones are created, forked and how they maintain their state across asynchronous operations. Zones are ...
0
votes
1answer
75 views

Is there a way I can make something happen on my nodejs server at a particular time

I'm not sure that I'm even asking the right question so I hope you guys can point me in the right direction here. I have a full stack web app which has listings (think eBay, Gumtree, Craigslist) and I ...
0
votes
1answer
105 views

Use nullable or undefineable as object type?

This come with a debate with my colleague that I'm using nullable object type. type Value = Node | null const [v0, setV0] = React.useState<Value>(null) const [v1, setV1] = React.useState&...
22
votes
8answers
7k views

Should child nodes have a reference to their parents?

Let's say you are engineering a chat room software. let client = new Client(); let room = rooms.FindRoom(); room.addClient(client); This room (parent) now has a client (child). client.on('message', (...
-1
votes
1answer
66 views

Mutexes at application logic level

In my node.js app I have a async function that fetches remote documents and caches them on the disk. Upon a retrieval request for a document first checks the disk, if found loads it from the disk ...
-2
votes
1answer
88 views

How to start developing a well architected Javascript Library?

I want to start developing an. open-source javascript library. I can see other open-source libraries are well structured. They have src, dist, test kind of folders, etc. Which is making me very ...
0
votes
0answers
71 views

Is XSS by html event injection a problem in this client-side sanitization?

I'm making my own client-side router which dynamically requests html pages from Firebase hosting, and the website uses Cloud Firestore with secure rules. Is there any XSS HTML event js injection ...
-3
votes
2answers
706 views

Should I use Flask w/ Javascript OR a Javascript UI that calls a Flask / Connexion API?

I recently wrote a data management tool in Python & SQLAlchemy. Now, I need to put a web UI on it. While I want to start small, there is some need for interactivity, like drag and drop in tables, ...

1
2
3 4 5
42