Literal and Constructor way of Creating Objects 3.2

 3rd Day                                                                                           See the source image

        QHey 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:           


                  2Constructor way of Creating Objects:

                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 its 
                        attributes like Var person = {}; is called literal way of creating objects.

                        After 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: Input
                                    
                             
   
Explanation:     In above Example, We made a function name Human and mention its attributes,                                      2nd things var men = new Human(); made on Human prototype , 
             Output: 
  • As well as men.run(); will give Men will run.
  • men.behave(); will give All human should have good behavior.
       




                                                           Thank You....


No comments:

Post a Comment