Issues (2242)

node_modules/once/once.js (2 issues)

1
var wrappy = require('wrappy')
2
module.exports = wrappy(once)
3
module.exports.strict = wrappy(onceStrict)
4
5
once.proto = once(function () {
6
  Object.defineProperty(Function.prototype, 'once', {
7
    value: function () {
8
      return once(this)
9
    },
10
    configurable: true
11
  })
12
13
  Object.defineProperty(Function.prototype, 'onceStrict', {
14
    value: function () {
15
      return onceStrict(this)
16
    },
17
    configurable: true
18
  })
19
})
20
21
function once (fn) {
22
  var f = function () {
23
    if (f.called) return f.value
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
24
    f.called = true
25
    return f.value = fn.apply(this, arguments)
26
  }
27
  f.called = false
28
  return f
29
}
30
31
function onceStrict (fn) {
32
  var f = function () {
33
    if (f.called)
34
      throw new Error(f.onceError)
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
35
    f.called = true
36
    return f.value = fn.apply(this, arguments)
37
  }
38
  var name = fn.name || 'Function wrapped with `once`'
39
  f.onceError = name + " shouldn't be called more than once"
40
  f.called = false
41
  return f
42
}
43