Opened 6 years ago

Closed 5 years ago

Last modified 5 years ago

#656 closed change (fixed)

Replace __proto__ with Object.create

Reported by: tschuster Assignee: tschuster
Priority: Unknown Milestone: Adblock-Plus-2.6.4-for-Firefox
Module: Adblock-Plus-for-Firefox Keywords:
Cc: trev, sebastian Blocked By:
Blocking: #427 Platform: Firefox
Ready: no Confidential: no
Tester: Verified working: no
Review URL(s):

http://codereview.adblockplus.org/5636077285015552/

Description

I am not yet 100% sure if we should really do this. Especially because code like this becomes ugly:

Foo = function () {}
Foo.prototype = {
  __proto__: Bar.prototype,
  foo: 1
}
/* vs. */
Foo = function () {}
Foo.prototype = Object.create(Bar.prototype)
Foo.prototype.foo = 1;
Foo.prototy ...
...

Change History (6)

comment:1 Changed 6 years ago by sebastian

  • Cc trev sebastian added

For reference: __proto__ is deprecated.

But I agree that using Object.create() makes code less readable in particular when using getter/setter:

Foo = function () {};
Foo.prototype = Object.create(
  Bar.prototype,
  {
    foo:
    {
      get: function()
      {
        return this._foo;
      },
      set: function(value)
      {
        this._foo = value;
      },
      enumerable: true
    }
  }
);

comment:2 Changed 5 years ago by trev

There are some cases where it makes sense to use Object.create(), especially {__proto__: null}. However, wherever we use it to build up class hierarchies we should better wait for typed objects.

comment:3 Changed 5 years ago by tschuster

  • Owner set to tschuster
  • Review URL(s) modified (diff)

comment:4 Changed 5 years ago by tschuster

  • Resolution set to fixed
  • Status changed from new to closed

comment:5 Changed 5 years ago by trev

  • Component changed from Unknown to Adblock-Plus-for-Firefox
  • Milestone set to Adblock-Plus-for-Firefox-next
  • Platform set to Firefox/Firefox Mobile

comment:6 Changed 5 years ago by philll

  • Platform changed from Firefox/Firefox Mobile to Firefox

Made Firefox and Firefox mobile available as seperate platforms.

Note: See TracTickets for help on using tickets.