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

Support 'local' bloodhound option as a function that returns an array #673

Closed
wants to merge 1 commit into from

Conversation

jmwong
Copy link
Contributor

@jmwong jmwong commented Feb 9, 2014

This addresses #485.

:)

var local = o.local || null;

if (_.isFunction(local)) {
local = local.call(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to use call here. Instead, you can just do:

local = local();

Also a shorter way of writing this would be:

function getLocal(o) {
  var local = o.local || null;

  return _.isFunction(local) ? local() : local;
}

Some people don't like the conditional operator, but I use it all the time. Really is just a preference call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that using .call(null) can prevent potential misuse of 'this' in the function that's being passed in (doesn't seem like it could happen now, but could guard against future changes)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a bad idea, but that would only make a difference in strict mode. In non-strict mode, both local() and local.call(null) will invoke local with the context set to the global object i.e. window.

This actually brings up a good point, should typeahead.js should run in strict mode? I'm thinking yes. I'm going to create a separate issue to track that change/discussion.

@jharding
Copy link
Contributor

This is a good looking pull request, thanks. I'll get this merged into the release branch.

If you get bored, feel free to pick off another issue 😃

@jharding jharding added this to the v0.10.1 milestone Feb 10, 2014
@jharding
Copy link
Contributor

Merged into integration-0.10.1 which will probably get released later today.

@jharding jharding closed this Feb 10, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants