Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

229
Views
Ampliación de una función jQuery existente

Estoy tratando de escribir un complemento que amplíe una función existente en jQuery, por ejemplo

 (function($) { $.fn.css = function() { // stuff I will be extending // that doesn't affect/change // the way .css() works }; })(jQuery);

Solo necesito extender unos pocos bits de la función .css() . Me importa que pregunte, estaba pensando en las clases de PHP, ya que puede className extend existingClass , por lo que pregunto si es posible extender las funciones de jQuery.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Claro... Simplemente guarde una referencia a la función existente y llámela:

 (function($) { // maintain a reference to the existing function var oldcss = $.fn.css; // ...before overwriting the jQuery extension point $.fn.css = function() { // original behavior - use function.apply to preserve context var ret = oldcss.apply(this, arguments); // stuff I will be extending // that doesn't affect/change // the way .css() works // preserve return value (probably the jQuery object...) return ret; }; })(jQuery);
over 4 years ago · Santiago Trujillo Report

0

De la misma manera pero un poco diferente a la mejor respuesta de esta pregunta:

 // Maintain a reference to the existing function const oldShow = jQuery.fn.show jQuery.fn.show = function() { // Original behavior - use function.apply to preserve context const ret = oldShow.apply(this, arguments) // Your source code this.removeClass('hidden') return ret }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!