答案一定很明显,但我没有看到
这是我的 javascript 类:
var Authentification = function() {
this.jeton = "",
this.componentAvailable = false,
Authentification.ACCESS_MASTER = "http://localhost:1923",
isComponentAvailable = function() {
var alea = 100000*(Math.random());
$.ajax({
url: Authentification.ACCESS_MASTER + "/testcomposant?" + alea,
type: "POST",
success: function(data) {
echo(data);
},
error: function(message, status, errorThrown) {
alert(status);
alert(errorThrown);
}
});
return true;
};
};
然后我实例化
var auth = new Authentification();
alert(Authentification.ACCESS_MASTER);
alert(auth.componentAvailable);
alert(auth.isComponentAvailable());
除了最后一个方法,我可以访问所有内容,它在 Firebug 中说:
auth.isComponentAvailable is not a function
..但它是..
最佳答案
isComponentAvailable
没有附加到您的对象(即不是其属性),它只是包含在您的函数中;这使它成为私有(private)的。
你可以在它前面加上 this
让它成为公共(public)的
this.isComponentAvailable = function() {
关于javascript - javascript中的类方法不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16063549/