Extending Object

Oriol Bugzilla oriol-bugzilla at hotmail.com
Sun Apr 24 01:43:43 UTC 2016


They are no necessary the same:

```js
var _Object = window.Object,
    Object = function() {};
class Foo1 {
  constructor() {}
}
class Foo2 extends Object {
  constructor() { super(); }
}
_Object.getPrototypeOf(Foo1.prototype); // _Object.prototype
_Object.getPrototypeOf(Foo2.prototype); // Object.prototype
```

You are able to shadow or replace `Object` with a custom constructor. And this constructor might use `this`, that's why `super()` is required.

> From: joe at trusktr.io
> Date: Sat, 23 Apr 2016 18:15:28 -0700
> Subject: Extending Object
> To: es-discuss at mozilla.org
> 
> Are the following examples the same? Is there any reason to extend
> Object manually?
> 
> ```js
> class Foo {
>   constructor() {}
> }
> new Foo
> ```
> 
> ```js
> class Foo extends Object {
>   constructor() { super() } // super() is required.
> }
> new Foo
> ```
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160424/651dc27a/attachment-0001.html>


More information about the es-discuss mailing list