Battle: How can I check the target of an item

I would like something special to happen whenever actor 1 uses an item on himself in battle.

I was looking at this function in Yanfly's Battle Engine core:

BattleManager.startAction = function() {
var subject = this._subject;
if (!subject) return this.endAction();
var action = subject.currentAction();
this._action = action;
if (!this._action) return this.endAction();
if (!this._action.item()) return this.endAction();
var targets = action.makeTargets();
this.setTargets(targets);
this._allTargets = targets.slice();
this._individualTargets = targets.slice();
this._phase = 'phaseChange';
this._phaseSteps = ['setup', 'whole', 'target', 'follow', 'finish'];
this._returnPhase = '';
this._actionList = [];
subject.useItem(this._action.item());
this._action.applyGlobal();
this._logWindow.startAction(this._subject, this._action, this._targets);
};

And there we have for example targets.slice(), but when I ask if it equals 1, it says "object object".

So, is there a way to check which actor was selected for item use in battle?
Yes, and you don't need JavaScript for that.

Have the item apply an invisible "item used" state to the target, and have it call a common event.
In the common event you use conditional branches on all actors to check which one has the state, then do what you want and remove the state.
$gameParty.prototype.targetActor()
returns actor
$gameParty.lastItem()
returns item

validate actor and item for the case in question, and you should be set.
It says "object object" because you're trying to use a javascript object (in this case, an array) in a place where something is trying to convert it to a string using toString.

I like @Andar 's solution. Another option is to use the damage formula in a creative way. For example, if you want the item only to heal Actor 1, you could choose the Damage Type HP Recover and put the following in the damage formula. (Without knowing exactly what effect you want to happen, I can't tell if this idea or Andar's is more appropriate for you.)
Code:
(b.actorId() == 1) ? 100 : 0;


$gameParty.prototype.targetActor()
returns actor
$gameParty.lastItem()
returns item

validate actor and item for the case in question, and you should be set.

Actually $gameParty doesn't have a prototype property, only Game_Party does, so $gameParty.prototype.targetActor() returns an undefined error.

If you go this route, what you'll want to use is $gameParty._targetActorId, which you can compare to the actor ID you want (in this case 1). However, this only appears to work for using the item from the Item Menu scene, not in battle.
Actually $gameParty doesn't have a prototype property, only Game_Party does, so $gameParty.prototype.targetActor() returns an undefined error.

JS is not my forte (yet)
I was only extrapolating from ruby.
but, you got the point I was aiming at.... that's close enough.

Original thread: https://forums.rpgmakerweb.com/threads/battle-how-can-i-check-the-target-of-an-item.88742/