Extract the arguments provided in the constructor invocation

Given

const anInstance = new Plugin({ a: 'path' })

Is it possible to retrieve the arguments passed to the instance?

anInstance./* some method */ === [{ a: 'path' }]

// or

someWrapper(anInstance) === [{ a: 'path' }]

Constraints:

  1. You are not allowed to modify the internal workings of Plugin: consider it as an external dependency.
  2. Plugin can accept multiple arguments of any type.
  3. You cannot store the initial arguments in an external variable like this:

    const config = { a: 'path' }
    const anInstance = new Plugin(config)
    

Context: My goal is to test a webpack plugin configuration. For instance:

module.exports = {
  plugins: [
    new wepback.DllPlugin({
      name: '[name]',
      path: path.join(buildDir, '[name].json'),
    })
  ]
}

I aim to verify the configuration provided to DllPlugin. The third restriction is in place to avoid exporting the configuration for each plugin solely for the purpose of testing.

If there's no straightforward way to accomplish my initial objective, I may have to resort to exporting those configurations as I currently see no alternative means of accessing them.

Answer №1

If you want to create a new class, you can do so by using the extend keyword.

function NewClass() {}

class ExtendedClass extends NewClass {
  constructor(...parameters) {
    super();
    this.parameters = parameters;
    for (let parameter of parameters) {
      console.log(parameter);
    }
  }
  getParameters() {
    return this.parameters;
  }
}

const instance = new ExtendedClass({ key: "value" });
console.log(instance instanceof NewClass, instance.getParameters());

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

Removing an element with a specific class that was created with Javascript can be done by clicking outside the box

I needed to eliminate an element that was created using JavaScript of a specific class when clicked outside the box. I have created a color-picker using .createElement and added a class to it. Now, my goal is to remove that picker whenever a click occu ...

Error encountered during the prerendering process on Vercel's Next.js build

While trying to compile my website on Vercel, I encountered a pre-rendering error during export. Does anyone know why this is happening and can provide assistance? Here is the link to my GitHub repository where all the code is stored: https://github.com/M ...

Guide to Implementing i18n-iso-countries Library in React

I am currently developing a React application and attempting to utilize the i18n-iso-countries package to retrieve a countries object in English where keys represent iso codes and values represent country names. This process is straightforward in Node.js, ...

Troubleshooting: Why jQuery is Not Functioning Properly in Conjunction

Currently, I am in the process of developing a friend search feature. This function operates effectively; upon entering a name in the search bar, individual user profiles appear in separate div containers with their respective images and names. Each profil ...

Issue with Element's Response to JQuery Click Event

After pulling elements from the database in PHP, I utilized Jquery to add Elements to the page. Each button has two classes; one for controlling the GUI and another for handling the click event of that specific button. Here is the code snippet: echo " ...

Command for Sniping with Discord.js

I am currently working on creating a snipe command using Discord.js in my bot. I have set up command handlers and everything seems to be working fine, including the on messageDelete event. However, I encounter an error when I delete a user message and try ...

What is the method for determining the coordinate range in a three.js environment?

When developing a scene using html and javascript, incorporating a camera, renderer, and displaying the scene in a browser, how can one determine the visible range of the scene? In a specific scenario where only a 2-dimensional x/y scene with objects is b ...

Using a function as a prop in Vue js to retrieve data from an API

I am facing an issue with a component that I want to decouple from the data fetching implementation. My goal is to be able to pass a data fetching callback as a prop. The reason for this is so that I can easily mock the data fetching process in storybook. ...

Conceal the block quotes while substituting with a newline

My HTML page contains numerous comments enclosed in blockquotes. I attempted to implement a feature that allows users to hide all the comments with just one click by using the following JavaScript code: const blockQuotes = document.getElementsByTagName(& ...

Using Dynamic Jinja HTML to Select Elements Dynamically

I have a unique system where forms are dynamically created based on values from a dictionary. Each form is assigned an ID corresponding to the key value and initially hidden. <div id="subforms" style="display: none" > {%for k, v in options.items() ...

Quick inquiry about referencing state variables in the render method in React Native

Initially, I assumed it was just a simple syntax error, but now I'm beginning to think that it might be related to a bigger concept concerning hierarchy and inheritance. I am currently working on an app in react native (expo) where I aim to display a ...

Requirements for using Angular JS and Node JS

With upcoming projects involving AngularJS and Node.js, I'm a bit apprehensive as I don't have much experience with JavaScript. Should I start by picking up a book on each technology, or is it essential to learn more about JavaScript first before ...

Obtain the view property access while invoking render function as a callback

When working with the guid variable in the render() function, I encountered a limitation where I could only pass it to the constructor. Here is an example of the code I used: app.views.CompanyView = Backbone.View.extend({ el: '#company-view' ...

Vue.js: Efficiently handling multiple buttons within a Dropdown menu

I am currently working on a Vue.js Project and have a Dropdown component. Here is the code snippet: <template> <v-menu close-on-click transition="slide-y-transition"> <template v-slot:activator="{ on, attrs }" ...

Node.js causing excessive CPU usage due to repeated gettimeofday calls

Recently, I encountered a situation with a long-running node.js process that would occasionally spike to 100% CPU usage and stop responding to requests. In an effort to diagnose the issue, I used strace to inspect the process and discovered a series of get ...

Having difficulty retrieving cookie from fetch() response

Many times, the issue of fetching cookies from a SO response has been raised on sites like: fetch: Getting cookies from fetch response or Unable to set cookie in browser using request and express modules in NodeJS However, none of the solutions provide ...

Establishing the JavaScript time and time zone using data stored in an SQL database and the ASP.NET code-behind page

I have a database field that indicates the user's timezone using integers, where anything greater than 0 represents an increased number of hours. My task is to showcase two different times on the user's screen For example: Your current time: " ...

Is it possible to achieve a file upload in splinter using Python?

A challenging task lies ahead with my web application, where users can upload XML-style files and make modifications directly in the browser. To test this scenario using Splinter, I need to ensure correct input (id="form-widgets-body"): https://i.sstatic ...

How come my script that is dependent on the viewport does not apply classes?

I created a code to add a class to a div, but it's not working as expected. I need help troubleshooting this issue. The code works fine on codePen, but not on my WordPress website. How can I make sure the browser executes this code properly? Link to ...

Searching through an array to isolate only image files

I am working with an array that contains various file types, all stored under the property array.contentType. I am trying to filter out just the images using array.contentType.images, I believe. Check out the code snippet below: const renderSlides = a ...