代码中Var name和this.name是否是指向同一地址
程序代码:
<!DOCTYPE html> <html> <body> <script> /** *在函数person中var name和this.name是否指向同一地址,当通过var name="ceshi"给name赋值之后再用this.name=name对name赋值 会发现name的值并没有改变依然是“ceshi” *请高手解释下var声明的name和this.name的关系,以及代码执行结果的说明, */ function person(name,age) { var name="ceshi";// var age; this.name=name; this.age=age; document.write("1-name = "+name+"<br/>"); document.write("2-age = "+age+"<br/>"); document.write("3-this name = "+this.name+"<br/>"); document.write("4-this age = "+this.age+"<br/>"); this.changeName=changeName; function changeName(name) { this.name=name; } } m=new person("Sally",48); document.write("5-name = "+m.name+"<br/>"); m.changeName("Doe"); document.write("6-name = "+m.name); </script> </body> </html>
[ 本帖最后由 dddebug 于 2015-9-28 16:01 编辑 ]