Sunday 10 July 2016

Which method will be called?

experimenting javascript on method overload

<!doctype html>

<html>

<body><table><tr onclick=”hello(this);”><td>56</td></tr></table></body>

<script>
  'use strict'
function hello(control){
  console.log('Overloaded');
  //console.log(control.tagName);
}

function hello(controla, controlb){
  console.log('Overloaded ha ha ha');
  //console.log(control.tagName);
}
function hello(){
  console.log(arguments);
  //console.log(control.tagName);
}
</script>

</html>

Interesting Result:

Method which ever is declared/written in last is called.

try to change the sequence and run it.

would like to know the reason, please leave reason in comment

No comments:

Post a Comment