Câu trả lời phải rõ ràng nhưng tôi không thấy nó
Đây là lớp JavaScript của tôi:
var Authentification = function[] {
this.jeton = "",
this.componentAvailable = false,
Authentification.ACCESS_MASTER = "//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;
};
};
sau đó tôi khởi động
var auth = new Authentification[];
alert[Authentification.ACCESS_MASTER];
alert[auth.componentAvailable];
alert[auth.isComponentAvailable[]];
Tôi có thể đạt được tất cả mọi thứ trừ phương pháp cuối cùng, nó nói trong Firebug:
auth.isComponentAvailable không phải là một chức năng
.. nhưng nó là..
Ngoại lệ JavaScript "không phải là một hàm" xảy ra khi có nỗ lực gọi giá trị từ một hàm, nhưng giá trị không thực sự là một hàm.Thông điệp
TypeError: "x" is not a function. [V8-based & Firefox & Safari]
Loại lỗi
Có chuyện gì?
Nó đã cố gắng gọi một giá trị từ một hàm, nhưng giá trị thực sự không phải là một hàm. Một số mã hy vọng bạn sẽ cung cấp một chức năng, nhưng điều đó đã không xảy ra.
Có lẽ có một lỗi đánh máy trong tên chức năng? Có thể đối tượng bạn đang gọi phương thức trên không có chức năng này? Ví dụ: JavaScript
var auth = new Authentification[];
alert[Authentification.ACCESS_MASTER];
alert[auth.componentAvailable];
alert[auth.isComponentAvailable[]];
3 không có chức năng var auth = new Authentification[];
alert[Authentification.ACCESS_MASTER];
alert[auth.componentAvailable];
alert[auth.isComponentAvailable[]];
4, nhưng đối tượng JavaScript var auth = new Authentification[];
alert[Authentification.ACCESS_MASTER];
alert[auth.componentAvailable];
alert[auth.isComponentAvailable[]];
5 không có.Có nhiều chức năng tích hợp cần một hàm [gọi lại]. Bạn sẽ phải cung cấp một chức năng để các phương thức này hoạt động đúng:
- Khi làm việc với các đối tượng
5 hoặcvar auth = new Authentification[]; alert[Authentification.ACCESS_MASTER]; alert[auth.componentAvailable]; alert[auth.isComponentAvailable[]];
7:var auth = new Authentification[]; alert[Authentification.ACCESS_MASTER]; alert[auth.componentAvailable]; alert[auth.isComponentAvailable[]];
-
8,var auth = new Authentification[]; alert[Authentification.ACCESS_MASTER]; alert[auth.componentAvailable]; alert[auth.isComponentAvailable[]];
9,var auth = new Authentification[]; alert[Authentification.ACCESS_MASTER]; alert[auth.componentAvailable]; alert[auth.isComponentAvailable[]];
TypeError: "x" is not a function. [V8-based & Firefox & Safari]
0,TypeError: "x" is not a function. [V8-based & Firefox & Safari]
1,TypeError: "x" is not a function. [V8-based & Firefox & Safari]
2,TypeError: "x" is not a function. [V8-based & Firefox & Safari]
3,TypeError: "x" is not a function. [V8-based & Firefox & Safari]
4,TypeError: "x" is not a function. [V8-based & Firefox & Safari]
5
-
- Khi làm việc với các đối tượng
TypeError: "x" is not a function. [V8-based & Firefox & Safari]
6 vàTypeError: "x" is not a function. [V8-based & Firefox & Safari]
7:TypeError: "x" is not a function. [V8-based & Firefox & Safari]
8 vàTypeError: "x" is not a function. [V8-based & Firefox & Safari]
9
Ví dụ
Một lỗi đánh máy trong tên hàm
Trong trường hợp này, xảy ra quá thường xuyên, có một lỗi đánh máy trong tên phương thức:
const x = document.getElementByID['foo'];
// TypeError: document.getElementByID is not a function
Tên chức năng chính xác là
const x = document.getElementByID['foo'];
// TypeError: document.getElementByID is not a function
0:const x = document.getElementById['foo'];
Chức năng được gọi sai đối tượng
Đối với một số phương thức nhất định, bạn phải cung cấp chức năng [gọi lại] và nó sẽ chỉ hoạt động trên các đối tượng cụ thể. Trong ví dụ này,
TypeError: "x" is not a function. [V8-based & Firefox & Safari]1 được sử dụng, sẽ chỉ hoạt động với các đối tượng
var auth = new Authentification[];
alert[Authentification.ACCESS_MASTER];
alert[auth.componentAvailable];
alert[auth.isComponentAvailable[]];
5.const obj = { a: 13, b: 37, c: 42 };
obj.map[function [num] {
return num * 2;
}];
// TypeError: obj.map is not a function
Sử dụng một mảng thay thế:
const numbers = [1, 4, 9];
numbers.map[function [num] {
return num * 2;
}]; // [2, 8, 18]
Chức năng chia sẻ một tên với một thuộc tính đã có từ trước
Đôi khi khi tạo một lớp, bạn có thể có một thuộc tính và một chức năng có cùng tên. Khi gọi hàm, trình biên dịch nghĩ rằng hàm không còn tồn tại.
function Dog[] {
this.age = 11;
this.color = "black";
this.name = "Ralph";
return this;
}
Dog.prototype.name = function [name] {
this.name = name;
return this;
}
const myNewDog = new Dog[];
myNewDog.name["Cassidy"]; //Uncaught TypeError: myNewDog.name is not a function
Thay vào đó sử dụng một tên thuộc tính khác:
function Dog[] {
this.age = 11;
this.color = "black";
this.dogName = "Ralph"; //Using this.dogName instead of .name
return this;
}
Dog.prototype.name = function [name] {
this.dogName = name;
return this;
}
const myNewDog = new Dog[];
myNewDog.name["Cassidy"]; //Dog { age: 11, color: 'black', dogName: 'Cassidy' }
Sử dụng dấu ngoặc để nhân
Trong toán học, bạn có thể viết 2 × [3 + 5] là 2*[3 + 5] hoặc chỉ 2 [3 + 5].
Sử dụng cái sau sẽ ném lỗi:
const sixteen = 2[3 + 5];
console.log[`2 x [3 + 5] is ${sixteen}`];
// Uncaught TypeError: 2 is not a function
Bạn có thể sửa mã bằng cách thêm toán tử
const x = document.getElementByID['foo'];
// TypeError: document.getElementByID is not a function
3:var auth = new Authentification[];
alert[Authentification.ACCESS_MASTER];
alert[auth.componentAvailable];
alert[auth.isComponentAvailable[]];
0Nhập mô -đun đã xuất chính xác
Đảm bảo bạn đang nhập mô -đun một cách chính xác.
Một thư viện trợ giúp ví dụ [
const x = document.getElementByID['foo'];
// TypeError: document.getElementByID is not a function
4]var auth = new Authentification[];
alert[Authentification.ACCESS_MASTER];
alert[auth.componentAvailable];
alert[auth.isComponentAvailable[]];
1Sử dụng nhập khẩu chính xác [
const x = document.getElementByID['foo'];
// TypeError: document.getElementByID is not a function
5]:var auth = new Authentification[];
alert[Authentification.ACCESS_MASTER];
alert[auth.componentAvailable];
alert[auth.isComponentAvailable[]];
2