Case: Prototype constructor

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        function Star(uname, age) {
            this.uname = uname;
            this.age = age;
        }
        // In many cases, we need to manually use the constructor property that points back to the original constructor 
        // Star.prototype.sing = function () { 
        //      console.log ( 'I can sing'); 
        // }; 
        / / Star.prototype.movie = function () { 
        //      console.log ( 'I will turn the movie'); 
        // } 
        Star.prototype = {
             // If we modified the original prototype object to the prototype object is assigned a objects, you must manually using the constructor refers back to the original constructor 
            constructor: Star,
            sing: function() {
                console.log ( ' I can sing ' );
            },
            movie: function() {
                console.log ( ' I will turn the movie ' );
            }
        }
        var LDH =  new new Star ( ' Andy ' , 18 is );
         var ZXY =  new new Star ( ' Jacky ' , 19 );
        console.log(Star.prototype);
        console.log(ldh.__proto__);
        console.log(Star.prototype.constructor);
        console.log(ldh.__proto__.constructor);
    </script>
</body>

</html>

 

Guess you like

Origin www.cnblogs.com/qtbb/p/11815847.html