Skip to content

Instantly share code, notes, and snippets.

View saipraveen-a's full-sized avatar
:octocat:
Working From Home

Sai Praveen saipraveen-a

:octocat:
Working From Home
View GitHub Profile
@saipraveen-a
saipraveen-a / README.md
Last active September 19, 2020 12:56
JavaScript Understanding the Weird Parts - Function Constructor Prototype

How is the Prototype set when an Object is created using the Function Constructor?

The process of creating an Object using the Function Constructor automatically sets the Prototype for the new Object thats created.

Every function in Javascript has some properties like NAME (optional for anonymous functions), CODE and prototype.

The prototype property of the function will be used as the prototype (proto) of any object that is created using the function constructor. In other words, jonh.proto is the same as Person.prototype

@saipraveen-a
saipraveen-a / README.md
Last active September 19, 2020 12:23
JavaScript Understanding the Weird Parts - Function Constructors

Function Constructors are one way of creating Objects in JavaScript. The other ways are Object literal syntax and using Object.create

It was added to appease Java Developers back in the late 90's.

What happens when we write new Person()?

When the Javascript Engine sees a new Operator, it creates a new Object of type Person and then passes this Object as the this value to the Execution Context of the Person() function thats invoked. Within the context of the execution,