我试图在对象中使用函数声明,但到目前为止还不能。我知道我可以在对象中使用函数表达式,但是可以使用函数声明来代替吗?
这有效:
var objContainer = {};
objContainer.callback = function(data) {
objContainer.server_date = data.responseXML.documentElement.getAttribute("answer");
alert("Object should have XML response: " + objContainer.server_date);
};
这不会:
var objContainer = {};
function objContainer.callback(data) {
objContainer.server_date = data.responseXML.documentElement.getAttribute("answer");
alert("Object should have XML response: " + objContainer.server_date);
}
我也尝试过使用对象文字表示法的函数声明,但它也失败了:
var objContainer = {
function callback(data) {
var objContainer.server_date = data.responseXML.documentElement.getAttribute("answer");
alert("Object should have XML response: " + objContainer.server_date);
}
};