Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
2
Reply
Javascript What is constructor function
tri_inn
Jun 29 2017 9:27 AM
195
Reply
tell me when js function will be called as constructor function ?
if we write a simple js function then it will be called as constructor function ?
function myFunction(a, b) {
return
a * b;
}
var x = myFunction(4, 3);
so tell me
myFunction
() will be consider as constructor function ? if no then describe the reason.
tell me why below js function is consider as constructor function ?
function person(first, last, age, eye) {
this
.firstName = first;
this
.lastName = last;
this
.age = age;
this
.eyeColor = eye;
}
var myFather =
new
person(
"John"
,
"Doe"
, 50,
"blue"
);
var myMother =
new
person(
"Sally"
,
"Rally"
, 48,
"green"
);
when new keyword will be used to call js function then it will be consider as constructor function ?
please guide me. thanks
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
how to stop parent div method calling
Global variable is not updated javascript