1. Built-in Constructor Functions
These are the built-in constructor functions provided by JavaScript.
- function Array()
- function Function()
- function Promise()
- function Object()
- function String()
- function Number(), etc.
2. Built-in Array Constructor Function
2.1 Default Properties and Methods
Properties:
- constructor
- length
- prototype, etc.
Methods:
- push()
- pop()
- splice()
- shift(), etc.
2.2 Creating an Array with the new Operator (Older way of writing)
Syntax:
let myArray = new Array(item1, item2, ...);
JAVASCRIPT
3. Prototype Property
The Prototype property will be shared across all the instances of their constructor function.
3.1 Accessing the Prototype of a Constructor Function
JAVASCRIPT
3.2 Accessing the shared Prototype of an Instance
JAVASCRIPT
3.3 Prototypal Inheritance
On calling the
new()
operator, all the properties and methods defined on the prototype
will become accessible to the instance objects. This process is called Prototypal Inheritance.4. Built-in Function Constructor Function
4.1 Default Properties and Methods
Properties:
- name
- length
- constructor
- prototype, etc.
Methods:
- apply()
- bind()
- call()
- toString(), etc.
4.2 Creating a Function with the new Operator (Older way of writing)
Syntax:
let myFunction = new Function("param1, param2, ...", function body);
JAVASCRIPT
5. Instance Specific and Prototype Properties
5.1 Prototype Properties/ Methods
The Prototype Properties/ Methods are the properties or methods common across the instance objects.
Examples:
- calculateAge
- displayGreetings
- displayProfileDetails
- calculateIncome
5.1.1 Adding a Method to the prototype
JAVASCRIPT
5.2 Instance Specific Properties/ Methods
The Instance Specific Properties/ Methods are the properties or methods specific to the instance object.
Examples:
- gender
- yearOfBirth
- friendsList
- name
JAVASCRIPT
Arithmetic Operations
Given a constructor function ArithmeticOperations in the prefilled
code and two numbers firstNumber and secondNumber as inputs,
add the following methods to the constructor function using the
prototype.
Method Description
ratioOfNumbers
It Should return the ratio of the
numbers
sumOfCubesOfNumbers
It Should return the sum of
cubes of the numbers
productOfSquaresOfNumbers
It Should return the product of
squares of the numbers.
Given an object trekkingKit in the prefilled code and item item as
an input,
write a JS program to add the method isKitContains to the
constructor function Trekking using the prototype.
The method isKitContains checks whether the trekkingKit
contains the given item .
Input
The input will be a single line containing a string item
Output
The output should be a single line containing a boolean value.
The Object.getOwnPropertyNames() method gives an array
containing the properties of the object.
This is How we can get prototype properties.