3rd Day
Q. Hey Guys, What is the Literal and Constructor way of Creating Objects and use?
A.1. Objects created using object literals are singletons. This means when a change is made to the object, it affects that object across the entire script. For Example
Input:
var person ={}; // This is called literal way of creating objects. this is also comes under prototypical language.
Output:
In this case, we make a function and its attributes and also make function's object,
which is called Constructor way of Creating Objects. For Example
Input:
Explanation: In above Example firstly we made an object name person and itsAfter that , We made a ,function Human() and its attributes and also make an object (Var obj = new Human()) is called Constructor way of an objects.
Output:
Prototypical: InputExplanation: In above Example, We made a function name Human and mention its attributes, 2nd things var men = new Human(); made on Human prototype ,
- men.behave(); will give All human should have good behavior.
No comments:
Post a Comment