87,994
社区成员
发帖
与我相关
我的任务
分享
/*用类实现这样的作用
function CurrentAnswer(num)
{
var current=num;
return "the currrnt answer is :"+current;
}
alert(CurrentAnswer(5));
*/
function CurrentAnswer(num)
{
var current=num;
this.newObject={
getCurrent:function ()
{
return "the currrnt answer is :"+current;
}
}
// return newObject;//为什么一定有这句话呢?
}
var curr=new CurrentAnswer(5);
var s=curr.newObject;
alert(s.getCurrent());
/*用类实现这样的作用
function CurrentAnswer(num)
{
var current=num;
return "the currrnt answer is :"+current;
}
alert(CurrentAnswer(5));
*/
function CurrentAnswer(num)
{
var current=num;
var newObject={
getCurrent:function ()
{
return "the currrnt answer is :"+current;
}
}
this.getNewObj=function(){
return newObject;
}
// return newObject;//为什么一定有这句话呢?
}
var curr=new CurrentAnswer(5);
var s=curr.getNewObj();
alert(s.getCurrent());

function CurrentAnswer(num){
this.current = num;
this.newObject = {
getCurrent: function(){
return "the currrnt answer is :" + current;
}
}
}
var curr = new CurrentAnswer(5);
alert(curr.newObject.getCurrent());