prototype Questions

12

Solved

I am exporting the following ES6 class from one module: export class Thingy { hello() { console.log("A"); } world() { console.log("B"); } } And importing it from another module: import {...
Olson asked 10/6, 2015 at 14:14

6

Solved

STORE = { item : function() { } }; STORE.item.prototype.add = function() { alert('test 123'); }; STORE.item.add(); I have been trying to figure out what's wrong with this quite a while. Why doe...
Comestible asked 20/10, 2009 at 4:9

6

Solved

I'm fairly new to the concept of JavaScript's prototype concept. Considering the following code : var x = function func(){ } x.prototype.log = function() { console.log("1"); } var b = new x(...
Diastyle asked 22/1, 2013 at 2:43

4

I've read a ton of materials about prototypes and understand inheritance in general. However, this is one thing that is bugging me and I cannot figure it out. On dmitrysoshnikov.com there is a simp...
Lotte asked 7/12, 2020 at 12:16

3

Solved

If I have a constructor Quo var Quo = function (string) { this.status = string; }; and then made a new object using var myQuo = new Quo("confused"); what would be the difference between: Quo...
Bis asked 21/12, 2013 at 23:12

18

Solved

I've come to a point where I need to have some sort of rudimentary multiple inheritance happening in JavaScript. (I'm not here to discuss whether this is a good idea or not, so please kindly keep t...
Vintage asked 6/2, 2012 at 16:19

5

Solved

Is there any possibility to change the __proto__ property of an object in IE9 or IE10? Or is MS still not planning to include it in their JS engine? I need it in a very special situation where I n...
Companionable asked 7/12, 2011 at 10:4

3

how to round using ROUND HALF UP in javascript? I am using Prototype JavaScript framework version 1.5.1_rc3, so I prefer to use it if available. If not, I appreciate also if you share it. Any guid...
Looseleaf asked 16/3, 2012 at 1:51

5

Solved

I'm currently enjoying the transition from an object oriented language to a functional language. It's a breath of fresh air, and I'm finding myself much more productive than before. However - ther...

2

Solved

After reading this documentation: http://es5.github.io/#x4.2.1 I was confused by the two prototype references on CF, and by this statement: The property named CFP1 in CFp is shared by cf1, cf2,...
Clarkia asked 23/8, 2013 at 23:27

3

Solved

I am trying to understand JavaScripts Prototypal nature and I am trying to create object inheritance without using class like constructor functions. How can I attach the prototype chain from Anima...
Merrymaking asked 9/7, 2012 at 1:33

2

Solved

Well I am curios to learn about prototypes in javascript and found many articles however i am not able to understand why am i not able to use prototypes in Object literals in javascript. As we all ...
Tannate asked 14/12, 2016 at 12:52

5

Solved

I try to extend JavaScript Math. But one thing surprised me. When I tried to extend it by prototype Math.prototype.randomBetween = function (a, b) { return Math.floor(Math.random() * (b - a + 1)...
Bathsheba asked 20/12, 2014 at 13:56

3

Solved

I have an array var arr = [' A ', ' b ', 'c']; and I want to trim the spaces from each of the element from array. It can be done by using Array.map as arr.map(function(el) { return el.trim();...
Antipasto asked 8/10, 2015 at 3:41

16

What's the difference between var A = function () { this.x = function () { //do something }; }; and var A = function () { }; A.prototype.x = function () { //do something };
Digestif asked 22/11, 2008 at 4:39

9

Solved

I'm new to JavaScript. New as far as all I've really done with it is tweaked existing code and wrote small bits of jQuery. Now I'm attempting to write a "class" with attributes and methods, but I'...
Perlaperle asked 25/10, 2010 at 3:48

3

Solved

function Ninja(){ this.swingSword = function(){ return true; }; } // Should return false, but will be overridden Ninja.prototype.swingSword = function(){ return false; }; var ninja = new Ninj...
Pyjamas asked 27/2, 2014 at 6:32

2

I would like to extend the TypeScript Map type in my react TypeScript app to allow me to use .map(), in a similar way as you might with an Array. I found this post that describes several methods, b...
Simonsen asked 30/11, 2022 at 13:4

4

I've always seen examples of Class.prototype.method, but never instances of this.prototype.method. For example: function Class() { this.prototype.method = function() { alert("is this allowed?");...
Acarology asked 2/3, 2014 at 4:42

0

This is about language design of JavaScript: why does JavaScript have both .prototype and internal .[[prototype]]? Why it doesn't always use read-write property .prototype instead of having hidden ...

7

Solved

So lets say I've added some prototype methods to the Array class: Array.prototype.containsKey = function(obj) { for(var key in this) if (key == obj) return true; return false; } Array.protot...
Ryley asked 10/7, 2009 at 4:22

34

Solved

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 also references via its __proto__ prop...
Importation asked 31/3, 2012 at 21:13

4

Solved

I need do add a method to a Javascript class using the new syntax. I tried this way: class X{ constructor() { this.a = 'b' } x(){ } } X.prototype.y = function (){ console.log('y') } var...
Alcohol asked 5/3, 2016 at 12:1

3

in the classfull-Style (c++) or in the traditional Design Patterns (GofPatterns) it is really clear, what is the difference between composition and inheritance and how it is implemented and when to...
Lynda asked 18/6, 2014 at 15:1

3

Solved

In Google Chrom's javascript, objects have a property named __proto__ that points to their prototype (or parent) object. var foo = {}; console.log(foo.__proto__ === Object.prototype); //returns t...
Izzo asked 1/12, 2016 at 21:41

© 2022 - 2024 — McMap. All rights reserved.