How to imitate polymorphism with SendMesseage function on Unity (with Javascript) ?

I’ve heard about that we can materialize function like polymorphism on Unity with using SendMessage function.
Like this …

chara.js    
// weapon would set something which have function "Attack()"
function Attack(weapon : GameObject) : void
{
	damage = weapon.SendMessage("Attack");
}


wp_sword.js  
function Attack() : float
{
	// calc damage with sword ...
	return damage;
}

wp_gun.js    
function Attack() : float
{
	// calc damage with sword ...
	return damage;
}

But I don’t know how to get the damage value with SendMessage.
How do I get the damage value when use SendMessage ?
Or are there any other recommended way to materialize polymorphism ?

SendMessage doesn’t work like that; notice that its return type is void. It doesn’t return the return type of the function that it calls, it only calls it on every MonoBehavior in your entire project where the provided function is implemented.

In any case, polymorphism in Unity doesn’t have to be ‘imitated’. You can achieve it in the usual manner with normal inheritance. Make a class that inherits from MonoBehavior and call it “Weapon”, implement Attack() in that class, then make two classes called “Gun” and “Sword” that both inherit from Weapon. Now both Gun and Sword have the Attack() function.