/* * JavaScript模拟实体类的实现 */ function User(){ this.name = ""; this.age = 0; //如果传入实参直接 初始化 if (arguments.length == 2) { this.name = arguments[0]; this.age = arguments[1]; } this.getName = function(){ return this.name; } th
/*
* JavaScript模拟实体类的实现
*/
function User(){
this.name = "";
立即学习“Java免费学习笔记(深入)”;
this.age = 0;
//如果传入实参直接 初始化
if (arguments.length == 2) {
this.name = arguments[0];
this.age = arguments[1];
}
this.getName = function(){
return this.name;
}
this.setName = function(name){
this.name = name;
}
this.getAge = function(){
return this.age;
}
this.setAge = function(age){
this.age = age;
}
}
var user = new User("zdw", 22);
alert("name:" + user.getName() + ",age : " + user.getAge());
user.setName("admin");
user.setAge(99);
alert("changed********name:" + user.getName() + ",age : " + user.getAge());
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号