The constructor initializes an instance object, whose prototype property inherits an instance object.

Method 1

Var p = new Play(); var p = new Play(); p.width=300; p.height=200; p.num=4; p.autotime=3; // method p.autoplay=function(){alert("play........" ) } p.test=function(){} alert(p.width); p.autoplay();Copy the code

Method 2

function play(){ var p = new Object(); p.width = 300; p.height = 200; p.num = 4; p.autotime = 3; p.autoplay = function(){ alert("play........." ) alert(this.num) } p.test = function(){} return p; } var obj = play(); alert(obj.width); obj.autoplay();Copy the code

Methods 3

function play(width,height,num){ this.width=width; this.height=height; this.num=num; this.autoplay=function(){ alert("#######"); } this.test-function(){} return this} var p = new play(300,200,8); alert(p.width); p.autoplay();Copy the code