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???
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);