| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Errors/Not_a_function | [Back] [Original] |
Get to know MDN better
JavaScript is not a function
TypeError: "x" is not a function. V8 & Firefox & Safari
TypeError
JavaScript Object map JavaScript Array
const x = document.getElementByID("foo");
// TypeError: document.getElementByID is not a function
getElementById
const x = document.getElementById("foo");
const obj = { a: 13, b: 37, c: 42 };
obj.map((num) => num * 2);
// TypeError: obj.map is not a function
const numbers = [1, 4, 9];
numbers.map((num) => num * 2); // [2, 8, 18]
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"); // TypeError: myNewDog.name is not a function
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' }
2 (3 + 5) 2*(3 + 5) 2(3 + 5)
const sixteen = 2(3 + 5);
console.log(`2 x (3 + 5) is ${sixteen}`);
// Uncaught TypeError: 2 is not a function
*
const sixteen = 2 * (3 + 5);
console.log(`2 x (3 + 5) ${sixteen}`);
// 2 x (3 + 5) 16
helpers helpers.js
function helpers() {}
helpers.groupBy = function (objectArray, property) {
return objectArray.reduce((acc, obj) => {
const key = obj[property];
acc[key] ??= [];
acc[key].push(obj);
return acc;
}, {});
};
export default helpers;
App.js
import helpers from "./helpers";
This page was last modified on 2025718 by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |