Home › Forums › General Issues › Extending field in JavaScript, can I call the parent method? › Reply To: Extending field in JavaScript, can I call the parent method?
When extending fields in JavaScript using ACF’s model system, it’s absolutely possible to call the parent method from within your extended method, similar to how you would in PHP with parent::method().
You can do this by using this._super() in your child method to invoke the parent method. For example, in your case, to extend the removeAttachment function, you could structure it like this:
javascript
Copy code
const ImageExtends = acf.models.ImageField.extend({
removeAttachment: function() {
// Call the parent method
this._super();
// Your extra logic here
console.log(“Doing extra work after removing attachment…”);
}
});
The this._super() call refers to the parent method, allowing you to avoid duplicating its logic. This should help you keep your calendar code clean and modular.
Hope this helps !
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.