Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Object #<Object> has no method 'apply' #20

Closed
mishaaq opened this issue May 9, 2013 · 1 comment
Closed

TypeError: Object #<Object> has no method 'apply' #20

mishaaq opened this issue May 9, 2013 · 1 comment
Assignees
Labels

Comments

@mishaaq
Copy link

mishaaq commented May 9, 2013

Minimal example:

var AModel = Backbone.Model.extend({
    mutators: {
        foo: {
            set: function(key, value, options, set) {
                set(key, 'bar', options);
            }
        }
    },
    defaults: {
        foo: 'baz'
    }
 });

Calling (new AModel()).toJSON() results with error as above.
In the function Mutator.prototype.toJSON there is an assumption the mutator has always get method defined (under 'get' key of the mutator object or the mutator is a 'getter' itself). This is obviously wrong and such a check should be added:

if (_.isObject(mutator) === true && _.isFunction(mutator.get)) {
    attr[name] = _.bind(mutator.get, this)();
} else if (_.isFunction(mutator)) {
    attr[name] = _.bind(mutator, this)();
}
@asciidisco
Copy link
Owner

Yep. I hit that problem recently.
That was one of the reasons I avoided to reference 'this' within a mutator function to the model itself.
Would you like to put together a pull request?

@ghost ghost assigned asciidisco Oct 30, 2013
asciidisco added a commit that referenced this issue Mar 28, 2014
Fixed #20: Can define only a mutated setter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants