Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
Programmer.prototype =
{
constructor: Programmer,
var A = function(){};
A.prototype = {b:2};
var a = new A();
console.log( a instanceof A, a.b ); // true 2
var A = function(){ this._field = "test" };
var a = new A();
console.log( a.constructor.toString() );
A.prototype = {}
var b = new A();
console.log( a.constructor.toString() );
var A = function(){};
var a = new A();
console.log( a instanceof A ); // true;
A.prototype = {}
new A();
console.log( a instanceof A ); // false;
Sample2.js (line 12): function () { this._field = "test"; }
Sample2.js (line 16): function Object() { [native code] }
var Mixin_Babbler =
{
say: function ()
{
console.log("My name is " + this.name + " and i think:'" + this.THOUGHTS + "'");
},
argue: function() { console.log("You're totally wrong"); }
};
А какое отношение примеси имеют к ООП?
object.prototype[prop] = mixins[i][prop];
bindMethod = function(mixin, prop) {
return function(){mixin[prop].apply(this, arguments)}
}
object.prototype[prop] = bindMethod(mixins[i], prop);
var oldFoo = mixin.Foo;
mixin.Foo = function(){
console.log('doing Foo!');
oldFoo.apply(this, arguments);
}
После того, как с классическим (от слова класс) наследованием в JS стало вроде-бы все понятно…
Javascript примеси для чайников