jQuery
HTML
CSS
JavaScript
PHP
SQL
WordPress
jQuery Reference

Quick Reference

The $.proxy() method takes an existing function and returns a new one with a particular context.

Method 1

				
					// testing is the existing function to be called
testing = function() {
    this.txt = 'This is the object property:';
    $('div').click($.proxy(this.myClick, this));
};

testing.prototype.myClick = function(event) {
    alert(this.txt + ' ' + event.currentTarget.nodeName);
};

var x = new testing();
				
			

Method 2

				
					var objPerson = {
    name: 'Frank Pug',
    age: 18,
    new: function() {
      $('p').after('Name: ' + this.name + '<br> Age: ' + this.age);
    }
  };
  
  // objPerson is the "context" (name of the object)
  // new is the "name" (object property to be changed)
  $('button').click($.proxy(objPerson, 'new'));
				
			

Syntax

				
					$(selector).proxy(function,context)

// or

$(selector).proxy(context,name)
				
			

Parameters

ParameterDescription
functionThe existing function to be called
contextThe name of the object where the function lies
nameThe existing function whose context will be changed (should be a property of the context object)

We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.

jQuery
HTML
CSS
JavaScript
PHP
SQL
WordPress

Why 1SMARTchicken?

This site was built and is maintained to benefit my autistic son.
See More →

My Son's Name is Johnny

He was diagnosed as autistic quite late, at age four...
His story

Buy Me a Coffee

Thanks for your support!

Feedback

If you see an error on the page or the code itself is incorrect or incomplete, or just plain wrong, please let us know. We’re always learning. NOTE: we do not sell your information and will not send you spam emails.