JavaScript
JavaScript 对象
changeName() 函数 name 的值赋给 person 的 lastname 属性。
源代码:
点击运行 »
<script> function person(firstname, lastname, age, eyecolor) { this.firstname = firstname; this.lastname = lastname; this.age = age; this.eyecolor = eyecolor; this.changeName = changeName; function changeName(name) { this.lastname = name; } } myMother = new person("Sally", "Rally", 48, "green"); myMother.changeName("Doe"); document.write(myMother.lastname); </script>
运行结果:
点击运行 »