Category "prototype"

Javascript Custom Array.prototype.method logs 'not defined' [duplicate]

So, I've never done this before, trying to add a method to the Array.prototype. See console.log statement below for usage. It keeps telling

Object() vs. Function()

It is my understanding that pretty much everything in JS is an object and that constructors are one way to make a new object. I know that data types like Array,

Why does a class have a "constructor" field in JavaScript?

A class is supposed to have a prototype field that supplies default fields. For example, prototype.constructor defaults to the constructor function (i.e., the c

how to solve Prototype Pollution issue in VS code

I installed a package that is related to my learning courses. the codes are released on 2018 and I updated all the versions on package-lock.json and package.jso

HTMLElementWrapper solution for extending prototype -- adding new functions

The problem is quite simple: add two functions to the HTMLElement which is on and off. The on functions works exact same as addEventListener The off functions w

Prototype members

What is the difference if we define a method in the constructor function or we define it in the prototype of the constructer? I know that if we define it in the

Parse JSON String into a Particular Object Prototype in JavaScript

I know how to parse a JSON String and turn it into a JavaScript Object. You can use JSON.parse() in modern browsers (and IE9+). That's great, but how can I t

Javascript prototype method "Cannot set property"

I'm always getting Cannot set property 'saySomething' of undefined but why? Am I making a mistake somewhere? var Person = new Object(); Person.prototype.saySo

React: Where To Extend Object Prototype

I created a pure React application using create-react-app. I would like to extend the String class and use it in one or more components. For example: String.pr

TypeError: app.get is not a function

I'm trying to use express in a prototype function ioServer() { } module.exports = ioServer; ioServer.prototype.start = function() { var app = requ

Creating a simple inventory system in JavaScript

I'm trying to make a simple text adventure/farming simulator, but I'm new to JavaScript and I'm stuck trying to plan out how my inventory system will work. The

__proto__ VS. prototype in JavaScript

This figure again shows that every object has a prototype. Constructor function Foo also has its own __proto__ which is Function.prototype, and which in turn a

How to properly set prototype?

I'm practicing an exercise in a book called Object-Oriented JavaScript. The exercise in chapter 5 contains the following 4 questions: Create an object call