js中的公有和私有屬性或方法 http://bbs.51js.com/viewthread.php?tid=67057&highlight=%2Bwinter 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://bbs.51js.com/viewthread.php?tid=67208&highlight=%2B%D4%C2%D3%B0 http://bbs.51js.com/viewthread.php?tid=30812&highlight=%2B%C6%FC%BA%EC%CD%A4你的好象实现不了任何一个类都可以自己obj.address的 LZ要的貌似是这样的一个效果<script type="text/javascript">var Employee = function () { var wc = this, address; wc.id = "00"; wc.name = "wc"; wc.setAddress = function () { address = Array.apply(null, arguments).join("\n"); }; wc.getAddress = { toString : function () { return address; } };};Employee.prototype = { showAll : function () { var wc = this, a = [], i; for (i in wc) if (!/function|array|object/i.test(typeof(wc[i]))) a.push(i + " : " + wc[i]); a.push("address : \n" + wc.getAddress); return a; } };var c = new Employee;c.setAddress("1", "2", "3");alert( c.showAll().join("\n------------\n"));</script> <script type="text/javascript">var Employee = function () { var wc = this, address; wc.id = "00"; wc.name = "wc"; wc.setAddress = function () { address = Array.apply(null, arguments).join("\n"); }; wc.getAddress = { toString : function () { return address; } };};Employee.prototype = { showAll : function () { var wc = this, a = [], i; for (i in wc) if (!/function|array|object/i.test(typeof(wc[i]))) a.push(i + " : " + wc[i]); a.push("address : \n" + wc.getAddress); return a; } };var c = new Employee;c.setAddress("1", "2", "3");alert( c.showAll().join("\n------------\n"));</script> 这个是简单格式的:DsetAddress这样的东西,只是希望付值的时候按照规定的格式走<script type="text/javascript">var Employee = function () { var wc = this, address; wc.id = "00"; wc.name = "wc"; wc.setAddress = function () { address = arguments[0]; }; wc.getAddress = function () { return address; };};var c = new Employee;c.setAddress("1\n2\n3");alert([ "id : " + c.id , "name : " + c.name , "address : \n" + c.getAddress()].join("\n-------------\n"));</script> var c = new Employee;c.address= "shanghai "alert(c.address) 除非规定用 get set function Employee(id,name,address){ var address = address; this.id = id; this.name = name; this.getAddress = function (){ return address; } this.setAddress = function (ads){ address = ads; }}var obj = new Employee(1, 'qiaobushi', 'niaolongshan');alert(obj.address);alert(obj.getAddress()); jquery 获取html标签的问题出错 推荐大家一个群...... Ext程序在Firefox中不能运行!! 如何将table的前几行几列锁定,其他部分自由滚动? 用vml画的polyLine 如何实现拖动 建了一个web开发群,欢迎大家加入。 如何动态控制marquee标记的滚动速度? 层有src或则href,location的参数吗?? 哪位有javascript参考手册CHM版?我本来有的误删了,以前那个lostinet也不能用了!! 比较搞笑的想法,可能永远也没法实现(改变地址栏的显示内容) CSDN上的高手都哪去了? JAVASCRIPT 实现表格对齐
你的好象实现不了任何一个类都可以自己obj.address的
<script type="text/javascript">
var Employee = function () {
var wc = this, address;
wc.id = "00";
wc.name = "wc";
wc.setAddress = function () {
address = Array.apply(null, arguments).join("\n");
};
wc.getAddress = {
toString : function () {
return address;
}
};
};Employee.prototype = { showAll : function () {
var wc = this, a = [], i;
for (i in wc)
if (!/function|array|object/i.test(typeof(wc[i]))) a.push(i + " : " + wc[i]);
a.push("address : \n" + wc.getAddress);
return a;
}
};var c = new Employee;c.setAddress("1", "2", "3");alert(
c.showAll().join("\n------------\n")
);
</script>
<script type="text/javascript">
var Employee = function () {
var wc = this, address;
wc.id = "00";
wc.name = "wc";
wc.setAddress = function () {
address = Array.apply(null, arguments).join("\n");
};
wc.getAddress = {
toString : function () {
return address;
}
};
};Employee.prototype = { showAll : function () {
var wc = this, a = [], i;
for (i in wc)
if (!/function|array|object/i.test(typeof(wc[i]))) a.push(i + " : " + wc[i]);
a.push("address : \n" + wc.getAddress);
return a;
}
};var c = new Employee;c.setAddress("1", "2", "3");alert(
c.showAll().join("\n------------\n")
);
</script>
setAddress这样的东西,只是希望付值的时候按照规定的格式走
<script type="text/javascript">
var Employee = function () {
var wc = this, address;
wc.id = "00";
wc.name = "wc";
wc.setAddress = function () {
address = arguments[0];
};
wc.getAddress = function () {
return address;
};
};var c = new Employee;c.setAddress("1\n2\n3");alert([
"id : " + c.id
, "name : " + c.name
, "address : \n" + c.getAddress()
].join("\n-------------\n"));
</script>
c.address= "shanghai "
alert(c.address)
function Employee(id,name,address){
var address = address;
this.id = id;
this.name = name;
this.getAddress = function (){
return address;
}
this.setAddress = function (ads){
address = ads;
}
}var obj = new Employee(1, 'qiaobushi', 'niaolongshan');
alert(obj.address);
alert(obj.getAddress());