28 Aug

Scope and Binding in JavaScript

Function x executions in the scope of object y.


var Car = function() { this.name = 'car'; }
var Truck = function() { this.name = 'truck'; }

var func = function() { alert(this.name); }

var c = new Car();
var t = new Truck();

func.apply(c);
func.apply(t);

Original Article
[tags]javascript,apply,call,binding[/tags]

Leave a Reply

Your email address will not be published. Required fields are marked *