Strange Behavior of call javascript -
i'm studying javascript, , found example on book
function saynameforall(label) { console.log(label + ":" + this.name); } var person1 = { name: "nicholas" }; var person2 = { name: "greg" }; var name = "michael"; saynameforall.call(this, "global"); saynameforall.call(person1, "person1"); saynameforall.call(person2, "person2");
this outputs:
"global:michael" "person1:nicholas" "person2:greg"
i understand how call
works, output of saynameforall.call(this, "global");
isn't global:michael
global:result
.
this code http://jsfiddle.net/rho3zyb4/
you're running code in jsfiddle, aren't you: http://jsfiddle.net/4g8q9yor/ - jsfiddle has assigned iframe name
javascript outputs result
- you're getting dom iframe name.
create file on local machine , you'll see correct output or try elsewhere: http://js.do/code/48143 outputs:
global:michael person1:nicholas person2:greg
Comments
Post a Comment