xDGameStudios

Veteran
Veteran
Joined
Sep 15, 2012
Messages
102
Reaction score
60
First Language
Portuguese
Hi everyone!

I'm trying something with no success :(

Let's look at the function, for example:


Game_Actor.prototype.isActor = function() {
return true;
};




I want to know the name of the function who called this one:


So I looked up and it seems that what I need is "arguments.callee.caller.name" so:
 


var alias = Game_Actor.prototype.isActor
Game_Actor.prototype.isActor = function() {
alias.call(this);
console.log(arguments.callee.caller.name);
};



but then I can't access the name!! nothing appears :(  I can access the arguments.callee.caller (it will return the code inside the function) but nothing more!!
Some help, here?!
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
866
First Language
German
Primarily Uses
This looks like very bad practice to me. Why would you want to know that?
 

xDGameStudios

Veteran
Veteran
Joined
Sep 15, 2012
Messages
102
Reaction score
60
First Language
Portuguese
This looks like very bad practice to me. Why would you want to know that?


Developing a plugin right now and have to alias a lot of functions! If I knew the caller... then I would only need to alias one, and do different things according to the caller :p  I thought it would be good performance wise. But if it is bad practice I'll do it the other way around! xD
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
866
First Language
German
Primarily Uses
arguments.callee is forbidden in strict mode, which i highly encourage you to use, so i suspect there's a reason for that.


Also, i would try to keep the number of aliased functions low, because they increase the possibility of incompatibilities with other plugins (though sometimes there's nothing you can do about that). Try to handle as much as possible inside your own plugin and if you absolutely need to add new properties/functions to existing classes, at least prefix them with your name or something unique.
 

xDGameStudios

Veteran
Veteran
Joined
Sep 15, 2012
Messages
102
Reaction score
60
First Language
Portuguese
"alias" is bad!? I thought "override" was bad! :/

 
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
866
First Language
German
Primarily Uses
It's not bad, but using call/apply comes with a performance cost and extending base functions always brings the risk of incompatibilities. It's good practice to stay inside your own plugin, as much as possible (also enforces OOP encapsulation, which is another good practice).
 

kentaromiura

Veteran
Veteran
Joined
Nov 1, 2015
Messages
46
Reaction score
26
First Language
English
Primarily Uses
arguments.callee is forbidden in strict mode, which i highly encourage you to use, so i suspect there's a reason for that.



The reason is merely because it's very slow as it prevents optimizations, for this reason trying to access it will throw a TypeError.


in Chrome/Webkit there's a console.trace method which can be invoked like console.log but contains the stacktrace,


this plus the fact that you can name your functions make it easy to debug

Code:
Game_Actor.prototype.isActor = function isActor() {
    console.trace("I am the original");
    return true;
};

var alias = Game_Actor.prototype.isActor
Game_Actor.prototype.isActor = function myOverriddenIsActor() {
    alias.call(this);
    console.trace("Hey, I just met you, and this is crazy, but here' s my stacktrace, so look me maybe")
};
 

Latest Threads

Latest Profile Posts

Anybody know how to make an enemy have a line of sight? I'm trying to make Persona-like enemies.
zomboars.jpg

Concept art

Zomboars- main enemies in my story
mutant pigs addicted to beer
SF_People1_3 added!
index.php

I haven't been on here in forever wow(missed my forum birthday T-T). Anyways, I'm dabbling in BGMs, here's something I'm actually willing to share.

Forum statistics

Threads
109,203
Messages
1,043,015
Members
141,711
Latest member
DamonAngel04
Top