Skip to content

_.bindAll doesn't bind prototype functions #243

Closed
@gavacho

Description

@gavacho

Example:

var MyExample = function() {};
MyExample.prototype.exampleValue = true;
MyExample.prototype.getExampleValuePrototype = function() { return this.exampleValue; }

var myInstance = new MyExample();
myInstance.getExampleValue = function() { return this.exampleValue; }

alert(myInstance.getExampleValue.apply({}));
alert(myInstance.getExampleValuePrototype.apply({}));
// result: both alert 'undefined'

_.bindAll(myInstance);
alert(myInstance.getExampleValue.apply({}));
alert(myInstance.getExampleValuePrototype.apply({}));
// result: getExampleValue alerts 'true', getExampleValuePrototype alerts 'undefined'

_.bindAll(myInstance, 'getExampleValuePrototype');
alert(myInstance.getExampleValue.apply({}));
alert(myInstance.getExampleValuePrototype.apply({}));
// result: both alert 'true'

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions