- <script type="text/javascript">
- function Animal(aname,age,weight){
- this.aname = aname;
- this.age = age;
- this.weight = weight;
- }
- function Animal.prototype.getAname(){
- return this.aname;
- }
- function Animal.prototype.setAname(aname){
- this.aname = aname;
- }
- function Animal.prototype.getAge(){
- return this.age;
- }
- function Animal.prototype.setAage(age){
- this.age = age;
- }
- function Animal.prototype.getWeight(){
- return this.weight;
- }
- function Animal.prototype.setWeight(){
- this.weight = weight;
- }
- var animal = new Animal('Andy',13,13);
- document.write(animal.getAge());
- animal.setAname('Chenzw');
- document.write(animal.getAname());
- </script>
使用JS编写一段面向对象的代码
最新推荐文章于 2022-11-03 16:35:28 发布