Storing objects in an array in javascript is storing the function

TemporaryFix

I have a custom object called pipe

function pipe()
{
    this.x = 800;
    this.width = 50;
    this.y = 450;
}

When I try storing pipes in an array its not storing the object, but the function.

function loop()
{
    var flappy = new player();
    for(var i = 0; i < 3; ++i)
    {
        var p = new pipe();
        p.x = (1 + i) * 266;
        pipes.push(pipe);
    }
    interval = window.setInterval(function() { updateLogic(flappy) } , 20);
}

If I try accessing a property of a pipe in pipes it says undefined.

var pipe = pipes[0];
console.log(pipe.x);
GregL

You put pipes.push(pipe) instead of pipes.push(p).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Javascript - Storing array of objects in hidden field

From Dev

Javascript Storing Multiple Data Objects In An Array

From Dev

Storing complex objects passed by servlet into an array in javascript

From Dev

Javascript Storing Multiple Data Objects In An Array

From Dev

Storing and reading objects in to objects or array

From Dev

Javascript array storing process

From Dev

Storing quiz questions in array of objects

From Dev

Unable to set object property in storing to an array of objects (JavaScript)

From Dev

storing a php array in a javascript array

From Dev

Javascript Recursive function. Wrong results while storing data in array

From Dev

Storing a function in json [Javascript/Coffeescript]

From Dev

Storing a function in json [Javascript/Coffeescript]

From Dev

storing the argument of a function in a variable in JavaScript

From Dev

JavaScript storing search matches in array

From Dev

Storing regex in an array is not working in Javascript

From Dev

Javascript storing multiple fields in an array

From Dev

Storing a Function

From Dev

Mongoose schema for storing an array of JSON objects for subdocuments

From Dev

localStorage not storing a stringed Array of JSON objects

From Dev

Storing in CoreData from Array of Dictionary objects

From Dev

Storing an array of objects in external JSON file

From Dev

Storing objects in an array and retrieving using PHP

From Dev

Storing nested javascript objects in redis - NodeJS

From Dev

Storing nested javascript objects in redis - NodeJS

From Dev

Storing a function inside a bash array element

From Dev

Storing roots of a complex function in an array in SciPy

From Dev

Storing SYSCALL functions in array of function pointers

From Dev

Storing a string array in a class member function and returning it

From Dev

Storing multiple function values in a string/array (Python)

Related Related

  1. 1

    Javascript - Storing array of objects in hidden field

  2. 2

    Javascript Storing Multiple Data Objects In An Array

  3. 3

    Storing complex objects passed by servlet into an array in javascript

  4. 4

    Javascript Storing Multiple Data Objects In An Array

  5. 5

    Storing and reading objects in to objects or array

  6. 6

    Javascript array storing process

  7. 7

    Storing quiz questions in array of objects

  8. 8

    Unable to set object property in storing to an array of objects (JavaScript)

  9. 9

    storing a php array in a javascript array

  10. 10

    Javascript Recursive function. Wrong results while storing data in array

  11. 11

    Storing a function in json [Javascript/Coffeescript]

  12. 12

    Storing a function in json [Javascript/Coffeescript]

  13. 13

    storing the argument of a function in a variable in JavaScript

  14. 14

    JavaScript storing search matches in array

  15. 15

    Storing regex in an array is not working in Javascript

  16. 16

    Javascript storing multiple fields in an array

  17. 17

    Storing a Function

  18. 18

    Mongoose schema for storing an array of JSON objects for subdocuments

  19. 19

    localStorage not storing a stringed Array of JSON objects

  20. 20

    Storing in CoreData from Array of Dictionary objects

  21. 21

    Storing an array of objects in external JSON file

  22. 22

    Storing objects in an array and retrieving using PHP

  23. 23

    Storing nested javascript objects in redis - NodeJS

  24. 24

    Storing nested javascript objects in redis - NodeJS

  25. 25

    Storing a function inside a bash array element

  26. 26

    Storing roots of a complex function in an array in SciPy

  27. 27

    Storing SYSCALL functions in array of function pointers

  28. 28

    Storing a string array in a class member function and returning it

  29. 29

    Storing multiple function values in a string/array (Python)

HotTag

Archive