Access object properties via closure vs. this (v2)

Revision 2 of this benchmark created on


Preparation HTML

<script>
  var ObjClosure = function(count) {
    var _count = 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
    this.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.