Which design pattern does Bootstrap v4 utilize for handling click events?

Trying to decipher this code snippet:

$(document).on(
Event.CLICK_DATA_API,
Selector.DISMISS,
Alert._handleDismiss(new Alert()) )

This particular piece is related to the Alert component:

https://github.com/twbs/bootstrap/blob/v4-dev/js/src/alert.js

I am curious about why we are passing a new Alert() on a click event rather than simply using an instance or letting event.target handle it in the listener.

Answer №1

Upon closer examination of the code, it was discovered that a new instance is passed as an argument because there was no existing Alert instance at the time of the click event. This approach proves to be quite elegant as it only creates an instance when necessary.

I also learned from other sources that the pattern being utilized here is for 'event delegation'.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What causes SomeFunction.prototype to appear as "SomeFunction {}" when viewed in the console?

This is the code snippet: function Person(){} console.log(Person.prototype); // Person {} console.log(Person.prototype instanceof Person); // false console.log(Person.prototype instanceof Object); // true The output shows Person {} for Person.prototype, e ...

Navigate to a precise section of the webpage, positioned at a specific distance from the top

When scrolling on my page, the static header moves along with the user. However, when I link to a specific div using the standard method, the div appears behind the header. I would like to utilize: <a href="#css-tutorials">Cascading Style Sheet Tut ...

Using the byte array to specify the img src

How can I set the img src property using a byte array stored in an Object? <img id="profileImage"> <spring:bind path="object.profilePicture"> <input type="file" name="profilePicture" id="profilePicture" path="profilePicture"> ...

Angular promise fails to resolve after an extended period of waiting for a response

My application is designed to send GET requests to my node/express server. In order to monitor changes in the server code, I have implemented a setTimeout function. While the promise function on the client side initially functions properly for a short peri ...

Guide on implementing router-link within a select option dropdown in a Vue.js application

a.vue <template> <div>hi i am component 1</div> </template> <script> export default { name: "a", }; </script> b.vue <template> <div>hi i am component 2</div> </template> <script> ...

What is the ideal location for storing Django manager code?

I have a question about Django patterns that is quite simple. Typically, my manager code is located in models.py. However, what should be done when models.py becomes overly extensive? Are there any alternative patterns available to keep the manager code se ...

Tips for utilizing the /foo-:bar pathway in Nuxt.js?

I am trying to utilize the router /foo-:bar in Nuxt. Do you have any suggestions on how I could make this work? I attempted using pages/foo-_bar.vue but it did not yield the desired results. ...

Clearing the filename in a file type input field using React

When using this input field, only video files are accepted. If any other types of files are uploaded by enabling the "all files" option, an alert will be displayed. While this functionality is working correctly, a problem arises if a non-video file is adde ...

Ways to verify user login through jQuery post method

I am currently working on a login test application that utilizes jQuery post and PHP. I'm encountering an issue where the application is able to read the input values but fails to send the data to server.php and consequently does not return any data. ...

Is the removal of the Vue-Router link happening when you click on the top app bar icon in Google Material

Review of the following code snippet: <!DOCTYPE html> <html> <head> <title>test</title> <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='vie ...

Updating MongoDB with an unknown object can be a challenging task, but there

In my current project, I have set up a Mongoose model as follows: const userSchema = new mongoose.Schema({ userID: { type: String, require: true, unique: true }, username: { type: String }, serverID: { type: String, require: true }, roles: ...

Managed the double-click event to select Snap.svg text

I am currently utilizing the snapsvg library for a project where I am implementing the dblclick event to trigger a browser window alert. However, when clicking on the svg canvas, not only does the alert pop up but some text on the canvas also gets selected ...

Converting a base64 string to a PNG format for uploading to an S3 bucket from the frontend

Feeling a bit overwhelmed here, hoping this isn't just a repeat issue. I've come across similar problems but none of the solutions seem to be working for me at the moment. I'm currently utilizing react-signature-canvas for allowing users to ...

JavaScript Build Failure: Linting Error Detected - no-constant-condition

I am encountering an error labeled as Unexpected constant condition no-constant-condition when attempting to compile this code. (The error is on a line indicated with >>>) This code operates based on user input. The variables commandVariable0 and ...

Implementing Multitouch for two draggable elements using Jquery

Two draggables are set up to function as joysticks. My goal is to capture an event for each joystick. Although I am using touch-punch library, it does not support multitouch. I tried creating my own listener but then I couldn't drag anymore. Any sugg ...

Dynamically load current components in Angular 2's final release

In my quest to dynamically load a component in the upcoming release version 2.0.0, I encountered some challenges. Previously, in RC5, I utilized the following code for loading: I created a directive responsible for loading the controls: import { Check ...

React slick does not display arrows when there are 4 or more photos

I am facing an issue where the next and previous arrows are not appearing when I have 4 or more photos on react-slick. However, they show up fine when there are 3 or fewer photos. You can view my code at this link: https://codesandbox.io/s/wyyrl6zz3l ...

What is the best way to retrieve the current time from an angular material Date picker?

I'm currently utilizing the Angular Material datepicker component found at https://material.angular.io/components/select/overview However, it seems to only display the date without the current time: Mon May 28 2018 00:00:00 GMT+0530 (IST) Is there a ...

Regular expression for identifying a specific attribute paired with its corresponding value in a JSON object

Below is a JSON structure that I am working with: 'use strict'; // some comment is going to be here module.exports = { property1: 'value1', property2: 999, }; I am looking to remove the property2: 999, from the JSON. I attempted ...

Validation for radio buttons in Bootstrap 4

Looking for assistance with form validation using Radio elements on a Bootstrap 4 page. I want to display an error message underneath the radio element: <div class="invalid-feedback">Please choose an option</div> Below is the code snippet wi ...