Convert distance event script from ruby to javascript

There is someone that can help me to convert this script from ruby to javascript to create a plugin?

This should check the distance from 2 entity.

Code:
class Game_Interpreter  def distance_to_event(event_id1 , event_id2 = nil)    if (event_id2 == nil)    x1 = $game_map.events[event_id1].x    y1 = $game_map.events[event_id1].y    x2 = $game_player.x    y2 = $game_player.y    return ((x2-x1).abs + (y2-y1).abs)  else    x1 = $game_map.events[event_id1].x    y1 = $game_map.events[event_id1].y    x2 = $game_map.events[event_id2].x    y2 = $game_map.events[event_id2].y    return ((x2-x1).abs + (y2-y1).abs)    end  endend
I don't know but when i try to open a topic I can't XD, anyway thx Shaz(for move in the correct section).
That's because you posted in the wrong forum.  You posted them all in JS Plugin Releases (which requires moderator approval of every new thread), not JS Plugin Requests.  I've moved this over there now for you.
This should do the job

Spoiler
(function() { Game_Interpreter.prototype.distanceToEvent = function(id1, id2) { var x1 = $gameMap.event(id1).x; var y1 = $gameMap.event(id1).y; var x2 = id2 ? $gameMap.event(id2).x : $gamePlayer.x; var y2 = id2 ? $gameMap.event(id2).y : $gamePlayer.y; return $gameMap.distance(x1, y1, x2, y2); };})(); 
Don't forgot when you're using it, you have to do "this.distanceToEvent(id1, id2)" without the "this." you'll get an error.
Thx you very much Quasi  🙂   🤘 you rock!

Original thread: https://forums.rpgmakerweb.com/threads/convert-distance-event-script-from-ruby-to-javascript.47267/