clFoo = function () {
this.setS = function(str) { this.s = str; return true; }
this.bar = function() { return 'Hier ist Sender Jerewan.'; }
this.tok = function(str) { return 'Stimmt es, dass ' + this.s + ' ... Im Prinzip schon. ' + str; }
};
oFoo = new clFoo ();
oFoo.s = 'Objekte schwierig sind?'
console.log ( oFoo.bar() );
console.log ( oFoo.tok('Aber manchmal nicht.') );
oFoo.setS( '"this" immer das Objekt meint?' );
console.log ( oFoo.bar() );
console.log ( oFoo.tok('Aber manchmal nicht.') );
node test.js
Hier ist Sender Jerewan.
Stimmt es, dass Objekte schwierig sind? ... Im Prinzip schon. Aber manchmal nicht.
Hier ist Sender Jerewan.
Stimmt es, dass "this" immer das Objekt meint? ... Im Prinzip schon. Aber manchmal nicht.