Calling a function from another object

Hello!

I have an array in the code of a button (Let’s call it A). But I was to add to that array from another button (Let’s call it B).

However, whenever I refer to the array in button B, I get an error. Is there a way to do this?

Thanks.

Hi!

If you initialize your array in A like this:

this.array = [1,2,3]

You’ll be able to access it from B like this:

A.array[3] = 4

Ok, I thought this would work for functions also…
Like.

function drive(car){

}

A.drive(honda)

No. JS is evaluating our code at run time using an eval function. The nomenclature should be as follows:

project.drive = function(car) {

}

project.drive(honda);

Amazing community to answer so swiftly. My kids love wick editor.

4 Likes

That is the idea. :blush:

2 Likes