Custom breakpoints for object properties in JavaScript

Debugging User Defined Object Properties in JavaScript

Hello there!

I'm interested in finding a JavaScript debugging tool or addon that allows me to set breakpoints on user defined object properties.

For example:

Let's say I have a JavaScript Object Literal like this:


var TextBox = {
    color:"gray",
    size:"100px",
    border:true 
}

Now, I want to be able to put a breakpoint on TextBox.color, so that I can track any modifications made to this property and identify which function is responsible for the change.

The breakpoint should trigger when:


TextBox.color = null;
or
delete TextBox.color;

Does anyone know if Firebug or Chrome Developer Tools offer this feature already?

I've come across breakpoints for HTML element removal and attribute modification, but not specifically for user defined object properties.

Thank you for your help!

Answer №2

Try using the following code snippet:

(function() {
    var element=TextElement; var value = element.style; 
    Object.defineProperty(element, 'style', { 
        set: function(newStyle) { debugger; value = newStyle; },
        get: function() { debugger; return value; } 
    });
})();

You can then execute this in your browser's console.

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

How to convert a flipped or transposed array into a dictionary in jq

My document is as follows: { "id":"06b6751f-5125-4e48-b588-fcc8ff56004f", "dni":"78081181" } { "id":"4bdcf9e9-4a3e-4e13-963d-1270b94955dc", "dni":"77834021" } I wa ...

Using Typescript to define classes without a constructor function

As I was going through the "Tour of Heroes" guide on the Angular website, I came across the following code snippet: class Hero { id: number, name: string, } const aHero: Hero = { id: 1, name: 'Superman' } console.log(aHero instanceof H ...

Stop submission of form using react by implementing e.preventDefault();

Having trouble figuring this out.... Which event should I use to bind a function call for e.preventDefault(); when someone clicks enter in the input tag? Currently experiencing an unwanted refresh. I just want to trigger another function when the enter k ...

What is the best way to automatically redirect to a different page once a video has finished playing after 10 seconds?

I'm working on creating an HTML page that will automatically redirect after 10 seconds once a video has finished playing. The issue I'm facing is that the page is currently redirecting as soon as it loads, rather than waiting for the video to fin ...

Avoid page refreshing when retrieving data using PHP and AJAX

In my current program, I am able to add data and insert it into the database. However, I am looking for a way to automatically send this data to another page or browser without refreshing. I have two browsers open, so how can I submit the data to the other ...

Newbie seeking assistance: Troubleshooting Nodejs error - ENOENT: no file or directory found. Can someone please help?

I attempted to follow an online course on YouTube, mirroring the steps of the instructor. When I encountered an error, I diligently re-watched the video segment multiple times, searched for solutions on Google, and read through numerous similar problems on ...

Requiring three parameters, yet received four

Encountering an error in the dashboard.tsx file while trying to implement a line of code: "const { filteredEvents, stats, tableApps, formattedDate } = filterData(dataAll, Prefix, listApp, dateSelected);" The issue arose with the dateSelected parameter resu ...

I could use some assistance in creating arrays from a JSON file that contain identical keys

Here's the data in JSON format: [ { "id": 1, "picture": "image-hero-paramour.jpg", "title": "Project Paramour", "subheading": "Project made for an art museum near Southwest London. Project Paramour is a stateme ...

What is the reason behind having all bindings resolved during each $digest cycle?

Upon placing a breakpoint on a bound function, I discovered that it is being triggered every cycle. This came as a surprise to me as the timer displaying a countdown on the page was updating other properties as well. The demonstration below showcases thre ...

Numerical computations performed within text fields

I am currently working on a script where I am trying to calculate the total of two different operations and then come up with an overall quote. However, I am facing an issue when it comes to combining these calculations. Please keep in mind that I am rel ...

Error encountered due to a circular reference in the dependency library

Whenever I attempt to run my application, I encounter the following error: > npm start Starting the development server... ts-loader: Using <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="42363b32273121302b323602716c776c71"& ...

Issues with merging styles in TinyMCE 4

I've exhausted all the current configuration options and I'm still unable to resolve this issue. My goal is to have the style tag appended to the selected element without generating an additional span. For example: <p>Hello World!</p> ...

I only need one array from a map that returns two promises with arrays

Currently, I am working on optimizing the process of adding food and drink to an order simultaneously. To achieve this, I have created a promise that resolves when both actions are completed. These promises are then nested within another promise, which res ...

Performing an AJAX request to check the page's return status every 5 minutes

I am looking to create a basic AJAX script, but I am unsure where to start. My goal is to have the script check the page "req.php?online_mode" every 5 minutes and determine whether it returns "true" or "false". If it returns "true", there won't be any ...

Next.js ensures that dynamic routes do not result in redirection to a 404 page

I am facing an issue with my Next.js project. I have a file named [pid].js and I also want to add a custom 404 page. However, when I place the 404.js file inside the /pages directory, it causes a problem. If I remove the [pid].js file, the 404 page works f ...

An issue arises when attempting to initialize an AngularJS global variable using a REST service

I am looking to establish a global variable called httpTimeout that will be initialized at the beginning. This variable will contain a Long value retrieved from a synchronous Rest Service call and will be utilized in various services. ( function () { &apo ...

Non-linear zoom scaling in Three.js OrbitControls.js

Let's dive into the world of this library I'm referring to: https://github.com/mrdoob/three.js/blob/dev/examples/js/controls/OrbitControls.js I've encountered a question that is puzzling me: The zoom functionality seems elusive to me. It a ...

When React Router and Context fail to cooperate

Trying to transfer data between sites has posed a challenge for me. To address this, I opted to utilize React Context by setting up a high-level Context named DataContext. However, the dashboard in use also relies on React Router. How can I successfully ...

The issue of the window.open method malfunctioning on Internet Explorer 9

Struggling to make it work in IE9: Note: I forgot to mention that $variable is coming from a $_GET request based on a drop down menu selection. I am currently offline, <a href="#" onclick="window.open('https://domain.com/contact-form?chatq=& ...

Alert message verification for empty checkboxes with "null" in JavaScript

I have integrated the native-validations library into my form validation process. Everything is working well, except for an error message that appears when I try to submit a group of checkboxes without selecting any. The error message displayed is "null". ...