Это очень полезно при выполнении обратных вызовов из запросов AJAX:
function Person(_id, _name) {
this.id = _id;
this.name = _name;
};
Person.prototype.sayHi = function(greeting) {
alert(greeting + " from " + this.name);
};
Person.prototype.loadFromAJAX = function(callback) {
// in this example, it's jQuery, but could be anything
var t = this;
$.get("myurl.php", function(data) {
callback.call(t, data.greeting);
});
};
На самом деле, это довольно дурацкий пример.
В jQuery есть множество его применений. Например, функция jQuery (). Get ():
get: function( num ) {
return num === undefined ?
// Return a 'clean' array
Array.prototype.slice.call( this ) :
// Return just the object
this[ num ];
}
Используются функции прототипа Array, но в контексте объекта jQuery.