question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

wrap-iife doesn't catch .call / .apply. JSCS does

See original GitHub issue

Tell us about your environment

  • ESLint Version: 3.5.0
  • Node Version: N/A
  • npm Version: N/A

What parser (default, Babel-ESLint, etc.) are you using? Default

Please show your full configuration:

/* global window */
/* eslint wrap-iife: ["error", "inside"] */
window.foo = (function() { return 1; })();
window.bar = function() { return 3; }.call(this, arg1);
window.baz = function() { return d; }.apply(this, args);

The following passes. window.foo is fine because it is wrapped in parens, but the others don’t require it.

I’d expect that the functions that are called using .call and .apply should also be wrapped in parens. That is the behavior of the corresponding rule in JSCS and I’d like to keep that behavior while converting: http://jscs.info/rule/requireParenthesesAroundIIFE

Proposal

The current proposal is to add a new boolean option called functionPrototypeMethods that will lint call and apply using the same inside or outside value. For example:

/* eslint wrap-iife: [2, "outside", { functionPrototypeMethods: true }] */

(function(){ foo(); }()) // ok
(function(){ foo(); }.call(bar)) // ok

(function(){ foo(); }).call(bar) // error, expected parens to be outside but they were inside

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:21 (21 by maintainers)

github_iconTop GitHub Comments

1reaction
not-an-aardvarkcommented, Sep 30, 2016

@TheSavior This issue is accepted now, so feel free to start implementing this (assuming you’re still interested in doing so).

1reaction
TheSaviorcommented, Sep 30, 2016

Updated the initial post with the current proposal

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to correctly wrap and call a function in an object
I am using jQuery to retrieve the JS element, but using document.getElementById would produce the same result. Second Approach. I did search for ......
Read more >
Decorators and forwarding, call/apply
The idea is that we can call cachingDecorator for any function, and it will return the caching wrapper. That's great, because we can...
Read more >
bind(), call(), and apply() are untyped #212 - GitHub
bind() returns type 'any' and does not type check it's arguments. e.g. var add = function (a: number, b: number) { return a...
Read more >
IIFE - MDN Web Docs Glossary: Definitions of Web-related terms
An IIFE (Immediately Invoked Function Expression) is a JavaScript function that runs as soon as it is defined. The name IIFE is promoted...
Read more >
How to Correctly Wrap a JavaScript Function - TrackJS
Wrapping JavaScript functions lets you add common logic to functions you do not control, like native and external functions. Many JavaScript libraries ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found