Javascript question on inheritance and prototypes

In jQuery library I found this line

jQuery.extend = jQuery.fn.extend = function() {

This kind of puzzle is me. I thought that this object automatically provides access to its prototype methods (in other words, if the method or var is not allowed on the object itself, it is checked on its prototype, then on the prototype prototype, etc.).

So, what is the reason for associating a function with both an object and a prototype? (in jQuery fn is a prototype alias).

+3
source share
1 answer

Magic prototypeis a property of constructors, not objects. The jQuery instance inherits extendfrom the prototype, but jQuery needs its own copy.

, , , . [[Prototype]], , Javascript (. ECMA-262 § 8.6.2 4.2.1). obj.constructor.prototype, [[Prototype]] - , (, Firefox Safari) __proto__, , , [[Prototype]]. , .

§ 4.2.1, :

alt text http://img121.imageshack.us/img121/3504/prototypes.png

CF - ; cf i CF. , CF Cf p, , Javascript. , Javascript , . , CF Function.

+6

Source: https://habr.com/ru/post/1722962/


All Articles