Pass on the invocation of a function for an angular object to an internal object

Is there a clever method to pass an angular object function call to the same function on an internal object?

This is my current setup:

var grid = $('#' + config.selector).w2grid(gridConfig);

angular.merge(this, {
   addData: addData,
   lock: lock,
   unlock: unlock,
   reload: reload,
   clear: clear,
   removeRow: removeRow,
   getRecord: getRecord,
   setRecord: setRecord,
   refreshRow: refreshRow,
   destroy: destroy,
   resize: resize,
   setData: setData,
   selectNone: selectNone,
   getSelection: getSelection
});


....

    function addData(data) {
        grid.add(data);
    }

    function lock(message) {
        grid.lock(message || '', true);
    }

    function unlock() {
        grid.unlock();
    }

    function reload() {
        grid.reload();
    }

    function clear() {
        grid.clear();
    }

I want to only keep overridden grid functions

var grid = $('#' + config.selector).w2grid(gridConfig);


    ....

        function addData(data) {
            alert('add data override');
        }

    ....

So when angularObject.reload() function is called, it should trigger grid.reload(), and if angularObject.addData() is invoked, it will call the overridden addData() function within the angular object.

Answer №1

While JavaScript offers out-of-the-box propagation, there is a certain charm in being able to do it manually.

    function InnerClass() {
         this.method = function() {

         }
    }

function OuterClass() {
    var decoratedClass = new InnerClass()

    this.method = decoratedClass.method.bind(decoratedClass)
}


var instance = new OuterClass
instance.method()

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

Getting information for a Pie Chart in React JS using State: A Step-by-Step Guide

Having just started using React, I've encountered some difficulties in dynamically passing data from my state to Chart.js. Ideally, I want the Pie chart to update automatically whenever a user updates the Textbox and requests the Output. I have stored ...

Triggering controller actions in JavaScript with bootgrid

How can I trigger a Bootstrap Modal that is located in a partial view within a controller using jQuery-Ajax and Bootgrid's JavaScript? var grid = $("#grid").bootgrid({ ajax: true, url: "/Currency/listCurrencyJson", formatters: { ...

Direct the /username path to /[user]/[tab].js instead of [user]/index.js in Next.js

My goal is to develop a user profile page that displays content based on the current tab the user is viewing. The tab is determined by what is provided in the URL (e.g. /username/tab1). The challenge I am facing is that one of the tabs the user can access ...

Is it possible to add a custom header to $resource in AngularJS before invoking an action?

Here's how I have defined my $resource: angular.module("MyApp").factory("account", ["$resource", function ($resource) { var userResource = $resource("http://localhost/api/account/:id", { id: "@id" }, { ...

The next/image component is not able to display images loaded from an external URL

When attempting to fetch images from a CDN, an error stating "hostname **** is not configured under images in your next.config.js" was encountered. Despite following the configuration guidelines provided on the official Next website, the issue persists. // ...

Struggling to show the results

Hey fellow programmers, I have a small challenge that I could use some help with. I'm working on a program that needs to determine the largest number among 4 inputs. The core code is set up correctly, but I'm struggling with displaying the result ...

"Waiting for results with Node.js and Mongo DB is like trying to catch a

I am currently working on developing a Web Api using NodeJs and MongoDB. One issue I have encountered is that my await statements are not being awaited, leading to unexpected behavior in my code. Code async find_nearby_places(lng, lat, tag, maxDistanc ...

Is it possible to subtract an integer value from an HTML SQL database?

Currently, I am in the process of learning HTML, PHP, and other programming languages. My latest project involves creating a SQL database in phpMyAdmin with names associated with integer values, such as: Nickname 20 Nickname 30 Bank 10, and so on. Now, ...

Encountering TypeError: Unable to access the 'query' property as it is undefined

As I dive into learning AngularJS and sending requests to a Web API backend, I encountered the following error message: angular.js:13424 TypeError: Cannot read property 'query' of undefined In my project, I have a productListController define ...

Having trouble getting the HTML5 Video to play using the AngularJS ng-src tag?

There seems to be an issue with AngularJS ng-src not working properly with the HTML5 Video element in this specific fiddle: http://jsfiddle.net/FsHah/5/ Upon inspecting the video element, it appears that the src tag is correctly filled with the appropriat ...

How should I fix the error message "TypeError encountered while attempting to import OrbitControls"?

Encountering error while attempting to import OrbitControls JS: import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls' const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window. ...

The async function defined in the angular.run() method did not run prior to the controller being executed

Recently, I've been experimenting with Angular and struggling to figure it out. The issue I'm facing is with running a $http method in app.run(). This method fetches rooms from the server and initializes it in $rootScope.rooms. However, in the co ...

The texture appearance becomes unusual when using a ThreeJS point light

I utilized ThreeJS, specifically React Three Fiber, to construct a 3D Canvas. After adding a glb model, point light, and ambient light, the outcome was disappointing. https://i.sstatic.net/6vHaOKBM.png Why does the texture appear so jagged? Could it be ...

Utilizing JQuery for responsive screen size detection coupled with the scroll top feature

I've been trying to incorporate a screen size parameter into the function below, but so far I haven't had any success. I seem to be stuck at this point. The code shown here is working correctly... $(document).ready(function(){ $( ...

Basic AngularJS application for showcasing the present date

I enrolled in a online course through edX focused on AngularJS. Unfortunately, I've hit a roadblock with one of the labs. The platform doesn't provide solutions and the support forum isn't very helpful, so I'm turning to this community ...

What is the best method for transferring selected <option> within <optgroup> from box A to box B simultaneously?

Looking at the image above, the bold fonts represent <optgroup>, and the list beneath each one is <option> inside a multiple select box. These data are fetched from a database using ajax. My question is: how can I select an <option> and ...

Send a string from an AJAX request to a PHP script

My goal is to retrieve a value from an input field, send it through ajax to PHP, and then store the data in a MySQL table. The database structure is already in place, so I just need to insert the values. Here is my JavaScript file: var address = $("input ...

AngularJS enthusiasts have the ability to curate a personalized list of favorites

I am looking to implement a feature in my application where users can create a favorite list based on their selection. The application utilizes a lengthy JSON file containing a multitude of text, which is loaded using $http.get(). Below is the code segment ...

Trouble sending data with jQuery AJAX request

I've been experimenting with an Ajax request, but I'm having trouble figuring out why this code isn't sending any parameters to the JSP and is throwing a NullPointerException. I've fixed my code now, thanks for the responses. var dfd ...

Using the JQuery .prop() and .attr() setter functions does not effectively manipulate dialog polyfill properties

Incorporating a simple dialog tag using GoogleChrome dialog-polyfill.js has been quite straightforward. <button id="dialog-show" class="mdl-button mdl-button--raised mdl-js-button dialog-button">Show Dialog</button> <dialog id="remove-inve ...