You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: 28_object_oriented_programming/3_constructor_function.js
+7-5
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,10 @@
1
1
// Constructor Function
2
2
3
-
// What is Construction Function?
3
+
// Backstory
4
+
// - In other programming language like C++ and Java.
5
+
// - We have to create a class then inside the class we need to declare constructor after that we can create an object (Instance/ Instance Object).
6
+
7
+
// What
4
8
// - Yes, in JavaScript, you can create constructor functions without using the class keyword or the constructor keyword. Instead, you can define a regular function and manually assign properties and methods to the newly created object using the this keyword.
// Inheritance: In JavaScript is a mechanism that allows one object to acquire properties and methods of another object. This is primarily achieved through the prototype chain.
3
+
// What
4
+
5
+
// Inheritance: In JavaScript is a mechanism that allows one object to acquire properties and methods of another object.
4
6
5
7
// Prototype: In JavaScript, objects have a special hidden property [[Prototype]] (as named in the specification), that is either null or references another object. That object is called “a prototype”:
6
8
7
9
// Prototype Inheritance: When we read a property from object, and it’s missing, JavaScript automatically takes it from the prototype. In programming, this is called “prototypal inheritance”.
8
10
9
-
// What
10
-
// - Prototype is object.
11
-
// - Other objects inherit properties and methods from the prototype.
12
-
// - Every object in JavaScript has a prototype.
13
-
14
11
// Why
15
12
// - The prototype system allows JavaScript to implement inheritance and to share properties and methods across instances.
16
13
// - This makes code reuse and object - oriented programming possible in JavaScript.
@@ -22,22 +19,22 @@
22
19
// - Yes, function is function.
23
20
// - In JavaScript everything is object.
24
21
25
-
functionregularFunction(parameter){
22
+
functionConstructorFunction(parameter){
26
23
console.log(parameter);
27
24
}
28
25
29
26
// Normally calling function
30
-
console.log(regularFunction("argument"));
27
+
console.log(ConstructorFunction("argument"));
31
28
32
29
// Adding property into function like an object
33
-
regularFunction.power=2;
34
-
console.log(regularFunction.power);
30
+
ConstructorFunction.power=2;
31
+
console.log(ConstructorFunction.power);
35
32
36
33
// Prototype in function
37
-
console.log(regularFunction.prototype);
34
+
console.log(ConstructorFunction.prototype);
38
35
39
36
// Note
40
-
// - Every object in JavaScript inherit properties and method of parent object. It continues.
37
+
// - Every object in JavaScript inherit properties and method of parent object. It's continues process.
0 commit comments