JS equivalent of .method().call()?

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
What's the JS equivalent of this rgss3 code?


Object.method:)method_name).call(params)


Thanks.
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
<method>.call(<thisarg>, [<param1>, <param2>, ...]);


See here: https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Function/call


The first parameter decides what "this" inside the method should point to. If you are running in strict mode, undefined or null will be left as-is, while in non-strict mode they will be replaced with the global window object.


Alternatively, you can use apply instead of call, which takes an array-like object for the parameters.
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
OBJECT.prototype.METHOD.call(this, PARAMS)
OBJECT.METHOD.call(this, PARAMS)


I think it would be like this, depending on how your methods are defined.


Methods are just properties of objects, and prototype isn't that special either. As long as you specify the scope, 
 
Last edited by a moderator:

Lemur

Crazed Ruby Hacker
Veteran
Joined
Dec 1, 2014
Messages
106
Reaction score
124
First Language
English
Primarily Uses
If you mean a dynamic name:

Code:
object[method]()
object[method].call()
object[method].apply()
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
Yeah I mean calling a dynamic method name since I mostly use them back in Ace instead of eval.
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD

Forum statistics

Threads
105,868
Messages
1,017,070
Members
137,577
Latest member
SadaSoda
Top