Объясните про prototype
В общем есть такая функция:
Function.prototype.method = function ( name, func ) { this.prototype[name] = func; return this; }; Object.method('showName', function(){ console.log(this.name) }); var o = {name:'Some'}; o.showName() в первой функции method расширяет прототип функции новым методом, но почему когда мы применяем method к Object, он расширяет Object новым методом, ведь по идее у Objecta нету доступа к methody ?! я походу Жэстачайшэ туплю) объясните плз) |
Цитата:
Цитата:
Function.prototype.method = function( name, func ) { this.prototype[ name ] = func; return this; }; alert( 'method' in Object ); // true alert( 'method' in Array ); // true alert( 'method' in String ); // true alert( typeof( Object ) === 'function' ); // true alert( Object.constructor ); alert( Object.constructor === Function ); // true alert( 'method' in Object.prototype ); // false Object.method('showName', function() { console.log( this.name ); }); var o = { name:'Some' }; o.showName(); |
|
Цитата:
|
спс)т.е если расширяем прототип функций, то и расширяется функция конструктор OBject, я прально понял?
|
Часовой пояс GMT +3, время: 15:16. |