I often need to pass methods from objects to other objects. However, usually I want this method to be bound to the source object (by application I mean that 'this' must refer to the source object). I know several ways to do this:
a) In the constructor of the object: ObjectA = function() { var that = this; var method = function(a,b,c) { that.abc = a+b+c }}
b) In object A, which was passed to objectB: objectB.assign(function(a,b,c) { that.method(a,b,c) })
c) Outside of both objects: objectB.assign(function(a,b,c) { objectA.method(a,b,c) })
I want to know if there is an easier way to pass methods related to their source objects.
source
share