日期:2014-05-16 浏览次数:20426 次
function fn( arg1, arg2,... ){ // do something } fn( arg1, arg2,... ); fn.call( context, arg1, arg2,... ); fn.apply( context, [ arg1, arg2,... ]);
<!--by oscar999 2013-1-17--> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <script> var func=new function(){this.a="func"} var newfunc=function(x){ var a="newfunc"; alert(this.a); alert(x); } newfunc.call(func,"inputParameter1"); /*alert are * func/inputParameter1; not newfunc/inputParameter1 */ </script> </body> </html>
function Person(name){ this.name = name; this.gender = "male"; } var person1 = new Person("MM"); var person2 = new Person("YY"); person1.gender = "female"; alert(person2.gender);// male </script>
<script> function Person(name){ this.name = name; } Person.prototype.gender = "female"; var person1 = new Person("MM"); var person2 = new Person("YY"); alert(person2.gender);// male </script>