0% found this document useful (0 votes)
44 views

Intermediate Javascript Notes

1. When a function is used with the new keyword, it creates a new object and sets that object's prototype to be the constructor function's prototype. 2. It sets the this value inside the function to refer to the newly created object. 3. If the function returns a non-object value, it will return the newly created object instead.

Uploaded by

Diddle
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Intermediate Javascript Notes

1. When a function is used with the new keyword, it creates a new object and sets that object's prototype to be the constructor function's prototype. 2. It sets the this value inside the function to refer to the newly created object. 3. If the function returns a non-object value, it will return the newly created object instead.

Uploaded by

Diddle
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

-

new

What happens when new is used with a function?


1 . creates a new object this : 3
Sets the objects inheritance be the
prototype to
prototype
2
property
.

of the
constructing function -

this .

proto-- ConstructingFunction prototype


3 if
. Checks the construction function returns anything other
than an object, away or
functions .
If so ,
the function
returns the newly constructe object .

4 .
returns this (the
newly constructed object) if there's
no return statement in the function body .

call
apply , ,

bind
·
use these to
explicitly set the value of this in

a
function .

·
use method of one object
a on another
·

prevents code duplication .

call
Function call -> set the this value
manually
fu .
call (param(
↑ pass in object that should
equal new this

fu call (obj Paraml


.

, ,

-
param 2)
L these Parameters
get passed to the function
after this is set to new
objects .

apply
·fr obi Fargl argeI)
.

apply , ,

-works the same as call except


pass awayin an of parameter as list

instead of
passing parameters one &
a time

You might also like