wrap-iife doesn't catch .call / .apply. JSCS does
See original GitHub issueTell 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:
- Created 7 years ago
- Reactions:3
- Comments:21 (21 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@TheSavior This issue is accepted now, so feel free to start implementing this (assuming you’re still interested in doing so).
Updated the initial post with the current proposal