0

why variable is initiated?

function person(name, age) { this.name = name; this.age = age; this.changeName = function (name) { this.name = name; } } var p = new person("David", 21); p.changeName("John"); document.write(p); >> result [object object] i want output [john 21] but it is initiated. why so that???

16th Aug 2016, 2:04 AM
배준경
배준경 - avatar
1 Resposta
+ 3
var and new must same. the contents of the brackets in quotation marks must be enclosed. and you can assign it to another variable or age. ex. var person = new person("david"); var age = ("21"); person.changeName("john"); document.write(person + age);
17th Aug 2016, 9:18 AM
HawkEye
HawkEye - avatar