构造函数
-
为什么要学构造函数?
function Star(name,age,sex){ this.name = name; this.age = age; this.sex =sex; this.sing = function(song){ console.log(song); } } var a = new Star("ysw",19,"女"); console.log(a.age) console.log(a["name"]) console.log(typeof(a)) a.sing("孤勇者");