[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Errors/Not_a_function [Back]  [Original]

TypeError: "x" is not a function - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

TypeError: "x" is not a function

JavaScript "is not a function"

TypeError: Object doesn't support property or method {x} (Edge)
TypeError: "x" is not a function

TypeError

Object JavaScript (Object) map JavaScript (Array)

JavaScript

js
var x = document.getElementByID("foo");
// TypeError: document.getElementByID is not a function

getElementById

js
var x = document.getElementById("foo");

Object

Array.prototype.map() Array

js
var obj = { a: 13, b: 37, c: 42 };

obj.map(function (num) {
  return num * 2;
});

// TypeError: obj.map is not a function

js
var numbers = [1, 4, 9];

numbers.map(function (num) {
  return num * 2;
});

// Array [ 2, 8, 18 ]

js
var Dog = function () {
  this.age = 11;
  this.color = "black";
  this.name = "Ralph";
  return this;
};

Dog.prototype.name = function (name) {
  this.name = name;
  return this;
};

var myNewDog = new Dog();
myNewDog.name("Cassidy"); //Uncaught TypeError: myNewDog.name is not a function

js
var Dog = function () {
  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;
};

var myNewDog = new Dog();
myNewDog.name("Cassidy"); //Dog { age: 11, color: 'black', dogName: 'Cassidy' }

2 (3 + 5) 2*(3 + 5) 2(3 + 5).

js
const sixteen = 2(3 + 5);
alert("2 x (3 + 5) is " + String(sixteen));
//Uncaught TypeError: 2 is not a function

*

js
const sixteen = 2 * (3 + 5);
alert("2 x (3 + 5) is " + String(sixteen));
//2 x (3 + 5) is 16

(helpers.js)

let helpers = function () { };

helpers.groupBy = function (objectArray, property) {
  return objectArray.reduce(function (acc, obj) {
    var key = obj[property];
    if (!acc[key]) {
      acc[key] = [];
    }
    acc[key].push(obj);
    return acc;
  },
{});
}

export default helpers;

App.js

import helpers from './helpers'


Web Proxy Viewer  |  New URL  |  Original Page