New object from prototype

suggest change

In JavaScript, any object can be the prototype of another. When an object is created as a prototype of another, it will inherit all of its parent’s properties.

var proto = { foo: "foo", bar: () => this.foo };

var obj = Object.create(proto);

console.log(obj.foo);
console.log(obj.bar());

Console output:

> "foo"
> "foo"

NOTE Object.create is available from ECMAScript 5, but here’s a polyfill if you need support for ECMAScript 3

if (typeof Object.create !== 'function') {
    Object.create = function (o) {
        function F() {}
        F.prototype = o;
        return new F();
    };
}
Source: http://javascript.crockford.com/prototypal.html

Object.create()

The Object.create() method creates a new object with the specified prototype object and properties.

Syntax: Object.create(proto[, propertiesObject])

Parameters:

Return value

A new object with the specified prototype object and properties.

Exceptions

A TypeError exception if the proto parameter isn’t null or an object.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Inheritance:
* New object from prototype

Table Of Contents
11 Arrays
12 Objects
14 Classes
16 Map
17 Set
24 Loops
27 Date
29 Scope
30 AJAX
35 Cookies
41 JSON
44 Fetch
45 Modules
46 Screen
47 Inheritance
64 Console
68 Symbols
73 Modals
76 Events
86 Proxy
89 WeakMap
90 WeakSet
102 Tilde