Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Javascript constructor()

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 101
    Comment on it

    Lets talk about a constructor. It is actually a function to serve the purpose of using as a constructor. You can write a function to use it as a constructor or call it as a normal function, or use it both ways.
    You can easily perform the task of creating multiple similar objects with the same properties and methods by using a constructor. Its absolutely right to say to call constructors a set of regular functions.
    However, they are meant to be used with the "new" keyword. As far as types of constructors are concerned, there are two - native constructors like and custom constructors.
    Array and Object are the examples of native constructors. With custom constructors you define properties and methods for your own type of object.

    <html>
        <head>
            <title>JavaScript constructor() Method</title>
        </head>
    
        <body>
    
            <script type="text/javascript">
            var num = new Number( 177.1234 );
            document.write("num.constructor() is : " + num.constructor);
            </script>
    
        </body>
    </html>
    

    this function will return;

    num.constructor() is : function Number() { [native code] }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: