我将如何调用一个在对象内部发出警报的函数?这是我到目前为止所得到的:
function ObjectAlert(a,b,c){
var obj = {};
obj.name = a;
obj.location = b;
obj.shout= function (){alert(c);};
return obj;
}
ObjectAlert("jake","here","alert");
我将如何调用一个在对象内部发出警报的函数?这是我到目前为止所得到的:
function ObjectAlert(a,b,c){
var obj = {};
obj.name = a;
obj.location = b;
obj.shout= function (){alert(c);};
return obj;
}
ObjectAlert("jake","here","alert");
ObjectAlert("jake","here","alert").shout();
或者
var OA = ObjectAlert("jake","here","alert");
OA.shout();
?
试试下面的代码。希望它能满足你的要求。。
function ObjectAlert(a,b,c){
var obj = {};
obj.name = a;
obj.location = b;
obj.shout= function (){alert(c);};
return obj.shout();
}
ObjectAlert("jake","here","alert");
或者,您可以尝试以下方法..
function ObjectAlert(a,b,c){
var obj = {};
obj.name = a;
obj.location = b;
obj.shout= function (){alert(c);};
return obj;
}
ObjectAlert("jake","here","alert").shout();
而且,也可以试试这个..
function ObjectAlert(a,b,c){
var obj = {};
obj.name = a;
obj.location = b;
obj.shout= function (){alert(c);};
return obj;
}
var shout = ObjectAlert("jake","here","alert");
shout.shout();
尝试这个,
var object = new ObjectAlert("jake","here","alert");
object.shout();
简直喜欢
var test = ObjectAlert("this","is","alert");
test.shout();
甚至更好/直接
ObjectAlert("this","is","alert").shout();
function ObjectAlert(a,b,c){
var obj = {};
obj.name = a;
obj.location = b;
obj.shout= function (){alert(c);};
return obj;
}
var myAlert = ObjectAlert("jake","here","alert");
myAlert.shout();
希望这可以帮助:
var obj = ObjectAlert('jake', 'here', 'alert');
obj.shout();