thisArg kullanımı


( ! ) Notice: Undefined index: description in /home/prototurk.com/public_html/app/controller/demo.php on line 171
Call Stack
#TimeMemoryFunctionLocation
10.0004368152{main}( ).../index.php:0
20.0032450000require( '/home/prototurk.com/public_html/app/controller/demo.php' ).../index.php:101

Prototürk'e geri dön
function Counter() {
  this.sum = 0
  this.count = 0
}
Counter.prototype.add = function(array) {
  array.forEach(entry => {
    this.sum += entry
    ++this.count
  }, this)
}

const obj = new Counter()
obj.add([2, 5, 9])
console.log(obj.count)
// 3 
console.log(obj.sum)
// 16