JavaScript does not support function overload __ block chain

Source: Internet
Author: User
An interesting question is found in learning javascript: Beginners think JavaScript is similar to Java when they first start learning, except that JavaScript is a weakly typed language; Interestingly, JavaScript does not support overloaded functions. If you write a function overload JavaScript like Java does not give an error, this is the interesting place---not supported but not wrong. So for a function with the same name, when the call is simply to call the last function, it's like the last function overwrites the previous function with the same name. You can look at an example:
	function Test (A, B, c) {return
		a+b+c;
	}


	function Test (A, b) {return
		a+b;
	}

	function test () {return
		' Hello world ';
	}

	Window.alert (Test (1,2,3));
	Window.alert (Test (1,2));
	Window.alert (Test ());
 

All three calls to the function call the last Test () function, which pops up "Hello world" ...
In fact, I think the JavaScript function is to support the number of variable parameters, but also weak type language, from these two points does not support the function overload.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.