Access object properties via closure vs. this

Benchmark created on


Preparation HTML

<script>
  var ObjClosure = function(count) {
    this.next = function() { return ++count }
  }
  var ObjSelfClosure = function(count) {
    this._count = count
    self = this
    this.next = function() { return ++self.count }
  }
  var ObjThis = function(count) {
    this._count = count
  }
  ObjThis.prototype.next = function() {
    return ++this._count
  }
  var objClosure = new ObjClosure(0),
      objSelfClosure = new ObjSelfClosure(0),
      objThis = new ObjThis(0)
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Access properties via closure
objClosure.next()
ready
Access properties via self closure
objSelfClosure.next()
ready
Access properties via this
objThis.next()
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.