Stack Exchange Network

Stack Exchange network consists of 175 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.

0
votes
1answer
132 views

Using custom mime type for drag'n'drop events or data attribute dilema

I am having a dilema on a html/js application I have been requestyed to handle drag'n'drop events in order to display a dropped image in a div if is not from images that are already displayed in my ...
0
votes
1answer
62 views

Thinking about a setup to work with react and front end development

On my team I'm working as a frontend developer in a React codebase. We're building an application and do everything in React. Before this I was actually always a backend developer. Now I have the ...
-1
votes
1answer
100 views

Design ideas for showing another website's page in my own website

I would like to show a web page from another website and show it on my website. I want to annotate some text on their website content. Conceptually I know what needs to be done: - I will capture their ...
2
votes
1answer
53 views

Where should I do integration tests in a multi package project

Background: I am working on a node project which consists of a core package and several addon packages. For the end product to work, the core package and atleast one of the addon packages should be ...
0
votes
2answers
660 views

Is there an advantage to using AJAX rather than a simple window.location?

When doing simple server updates or submitting forms or that type of thing, I have come to a fork in the road...using AJAX: var ajax = new XMLHttpRequest(); ajax.open("post", "myserver.php", true); ...
-2
votes
1answer
467 views

Choosing the right architecture for my web application

I've started working on my web application and I'm stuck at the design stage. I cannot decide which web technologies would be the most suited to this project. Let me explain what I want to achieve: 1)...
0
votes
1answer
161 views

Using CSS classes to express state

Is it good practice to express the state of an HTML element--such as whether an input's value is valid--using a CSS class? Would it be better practice to use data attributes, the properties of a ...
1
vote
0answers
1k views

What are the best practices for picking selectors for web scrappers?

The following is an example using https://github.com/GoogleChrome/puppeteer 'use strict'; const puppeteer = require('puppeteer'); (async() => { // const browser = await puppeteer.launch(); // ...
4
votes
1answer
171 views

Proper way of throwing errors in a JavaScript library?

Let's say I am writing a simple library in JavaScript, with only a few functions: Calculate the factorial of a positive natural number Find the least common multiple from an array of integers And so ...
-3
votes
2answers
467 views

Are Java and JavaScript converging? [closed]

It seems to me that Java was the computing language that could be used anywhere and JavaScript was the scripting language for the web and things stayed that way for a long while. There are countless ...
0
votes
3answers
467 views

Code pattern to have the least possible code complexity (Javascript)

I've been looking for the ideal coding patterns used to score well in a Cyclomatic Complexity. Of course, code will be subject to change according to what is being developed but regardless the ...
-1
votes
2answers
618 views

Consuming Web API in website with role based views

I understand Web API. I understand websites, how they call a web API and all the good stuff. My question is, how do you control the user view in the website consuming the API, based on the API ...
0
votes
1answer
167 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 ...
2
votes
1answer
309 views

Pros and cons of different ways to create objects in Javascript [closed]

Context I am writing a JavaScript library, and I am finding that I don't know what the best way to support object creation. I came up with a list things that I am considering: var obj = Library....
-3
votes
1answer
56 views

Adding links to posts using RegEx - should it be server side or client side?

I am working on adding a feature to a forum where I look for keywords in posts and add links to these keywords. For example, say a user's post includes the phrase "HP Printers". This phrase would be ...
0
votes
1answer
78 views

What to test in this module?

Aside from the probable dozens of bugs you can spot in the code below, I'd really like to know what would most people would consider testing in the code below. I have 8 similar exported functions, so ...
2
votes
1answer
183 views

Describing JS program flow in @fileoverview

I have to edit other people's JavaScript code. The code usually loads some data from a Web API, generates a table, places it into the HTML page, and attaches some event handlers. Due to the async ...
1
vote
3answers
1k views

Object.defineProperty vs get/set

What is the difference and when would you prefer to use Object.defineProperty vs get/set methods in javascript for getters / setters? Ex: class Foo { constructor () { Object....
-4
votes
1answer
138 views

Rewrite legacy code or continue to live with it [duplicate]

Last year I decided to create a web-based SAP Business One extension system consisting of a JavaScript SPA written with Aurelia that communicates with two REST backends written in Go and Java (...
3
votes
2answers
233 views

I keep bouncing from “god function” to “tiny SRP functions” how do I break this cycle?

This question is important for me in growing in my technical abilities. I find I swing from end-to-end, like a pendulum, in writing code that is simultaneously DRY yet readable & efficient. And I'...
1
vote
1answer
633 views

Unit testing rabbitmq messaging library?

I'm having trouble figuring how I would test a library that intended to be used for communicating with another web service. For example, I have a Messenger class that initializes a connection and ...
2
votes
3answers
3k views

Time zone conversions on back-end or front-end

I have a web app with an ASP.NET API back-end and React front-end. It also has a mobile app built in React Native. Question is about date/time values. I have two options in handling time zone ...
1
vote
1answer
204 views

how to create API's from mere programming language

all programming languages have api's to interact various systems as a example javascript languge has Dom api to interact with the web page. C language languge has file access api to interact with ...
1
vote
1answer
58 views

Do events/functions need to be redefined at each level for an API?

I typically write code that only I use, but I do have a public github with some JS libraries. A key component of most libraries are events. My question may be opinionated, but I don't know where else ...
1
vote
3answers
581 views

Looking for a way to handle Javascript file dependencies

I'm making the transformation from being a web developer whose pages often contain loads of <script> tags to one whose pages contain modular Javascript, encapsulated in functions, etc. I'm ...
0
votes
1answer
53 views

Binding an interface on top of third-party modules to develop future-proofed and scalable apps

Every day a couple of new javascript modules are created and published around the world and we need to think long term. Let's say today I need to use an ORM module to go smooth and fast. But tomorrow ...
0
votes
1answer
35 views

Real time update as user entering information like what Google doc do or use a save button

I am making a design decision to real time hit API to save all the fields in a form when user make an change even if hes not finished yet. Or, use a save button like most app does. Any pros and cons ...
3
votes
2answers
556 views

What is the right time to go for Code Refactoring, not optimization?

I've been working on a Python(Django)/JavaScript(AngularJS) based application for some time now.(I learnt all of these on the way, had previously been a Java only programmer)and have hit moments where ...
0
votes
1answer
78 views

architecture - relation of scraper and orm classes

Consider the following application structure. The scraper class extracts the necessary information from a page, and I want to save it to the DB. The ORM class is a wrapper around sequelize.js. It ...
1
vote
2answers
198 views

Declaring a function without named parameters that accepts at least 1 argument

Say I have a function whose first parameter is used differently depending on how many arguments are passed. In this case, it is easier to just process the arguments object as a whole within the ...
1
vote
1answer
79 views

Styling shareable React component?

I've been looking for a good way to style a react component just using css stylesheets. I would have used style-loader, because it's as easy as require('./style.css') and allows to save the final ...
1
vote
1answer
472 views

HTML and iframe organization for dashboards [closed]

I need to build a small website for my ops team that will have a series of iframes pointing to a couple of Kibana graphics. The website will have, lets say, 4 links, each pointing to a a specific ...
1
vote
2answers
75 views

Refresh web page VS 'caching' idea tradeoff when creating/retrieving/updating/deleting (CRUD) data between web app and database

Design 1: For a web application. In the past, if I insert a record/data in UI, I will save this new data to the database, then the UI will be reloaded (like clicking browser refresh icon), but this UI ...
3
votes
2answers
465 views

Mixing JavaScript and server-side scripting

I see code like this sometimes (mixed PHP and JS in this case, but could be any server-side language): <script> var data = <?php echo $bigDataStructure ?>; // then lots more pure js ...
4
votes
1answer
462 views

How to implement option to return Blob, ArrayBuffer, or AudioBuffer from window.speechSynthesis.speak() call

Note, presently have no experience composing or modifying C++ code, which the code that will need to compose or modify is written in. Specifically, window.speechSynthesis.speak() does not currently ...
0
votes
1answer
188 views

Best practices for creating multiple HTML buttons that are used for a similar purpose

I realize this may be subjective, but I don't see any clear-cut place for asking questions on good software design principals. I'm sure there are some software patterns and anti-patterns I should be ...
1
vote
1answer
305 views

Would onpushstate be an anti-pattern?

In Single Page Applications, it's common to update the URL when navigating, and re-render based on the new URL. This can happen when the user hits the back and forward button, clicks on an anchor tag, ...
0
votes
1answer
714 views

Best practice to callbacks in OOP (JavaScript)?

For anyone who uses callbacks, how do I approach it when the method is an asynchronous setter? Here's an example class API { constructor() { this.token = null; } refreshToken(callback) ...
0
votes
1answer
55 views

Breaking apart a large javascript application that uses the object namespacing pattern

I have a mission critical Backbone application built before AMD and CommonJS were widely used. This application makes heavy use of the Object Namespacing pattern, so that that all the views, ...
6
votes
2answers
2k views

Why does Facebook obfuscate the names of CSS classes?

If you look at the source code of a website such as Facebook, you'll see many classes as such: <div class="_cy6 _2s24"><div class="_4kny"><div class="uiToggle _8-a _1kj2 _4d1i _-57 _5-...
2
votes
1answer
61 views

Should I place my app configurations in a JSON file or in a JS module?

I am building a JavaScript application where its behavior (some rules and logic) is configurable via JSON. The configurations are deploy only with a new version of the app. Currently my app, when ...
1
vote
2answers
556 views

High order functions: What's the benefit returning a function compared to a value?

In order words, what's the advantage of writing this: Listing 1 var sortBy = function sortBy(p) { return function (a, b) { return a[p] > b[p]; }; }; Compared to this? Listing 2 var ...
0
votes
1answer
275 views

ES6 and OO Desighn: It is good idea to use a class as “Interface”?

Usually on Php or in Java and in other single Inheritance Object Oriented Languages, when I am writing a software I use and Interface then and afterwards I implement the class that implements the ...
0
votes
1answer
141 views

load more and Search Logic

Firstly i hope im in the right place to ask this question. I am building a web page that allows the user to select one image from a set of a 100+. i want to display them 6 at a time and the user ...
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 ...
1
vote
2answers
936 views

JS: convention to distinguish immediate vs async methods

I normally have a laissez faire attitude on method naming conventions but now I am working on a module in JavaScript that will have some methods that can return the value directly (immediate / plain ...
1
vote
0answers
372 views

Pre-rendering a lot of images in HTML5 canvas, good idea?

A lot of things on the internet are very conflicting on how to deal with things. Here's my situation: I'll be building a client in javascript, using the HTML5 canvas, the canvas will contain ...
0
votes
2answers
126 views

Do Adobe PDF Actions get detected as JavaScript?

My company is creating a PDF survey (intended for other companies to complete) and we're trying to make the solution interactive (conditional checklists that become visible based on the status of ...
1
vote
0answers
47 views

How do I protect JS local scope but allow outside customization?

I am creating a javascript application that will live in a library and be used on multiple sites. I am looking for it to have the following features and need some guidance on accomplishing these goals:...
8
votes
4answers
4k views

Better ways than traditional polling methods

I'm currently in a AngularJS/Javascript environment. Currently the application using the polling method (i.e, to retrieve new data from server in a fixed amount of seconds). This is quite taxing ...