Skip to content

Commit 75229c1

Browse files
author
Galeel Bhasha Satthar
committed
Simplified the usage by self invoking the function when it isrequired or imported
1 parent 987e7c9 commit 75229c1

2 files changed

Lines changed: 19 additions & 18 deletions

File tree

CustomEvent.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
function CustomEvent ( event, params ) {
2-
params = params || {
3-
bubbles: false,
4-
cancelable: false,
5-
detail: undefined,
6-
};
7-
var evt = document.createEvent( 'CustomEvent' );
8-
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
9-
return evt;
10-
}
1+
(function() {
2+
if (typeof window === "undefined") return false;
3+
if (typeof window.CustomEvent === "function") return false;
4+
5+
function CustomEvent ( event, params ) {
6+
params = params || { bubbles: false, cancelable: false, detail: undefined };
7+
var evt = document.createEvent( 'CustomEvent' );
8+
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
9+
return evt;
10+
}
1111

12-
module.exports = function ( undefined ) {
13-
if ( typeof window.CustomEvent === 'function' ) {
14-
return;
15-
};
1612
CustomEvent.prototype = window.Event.prototype;
13+
1714
window.CustomEvent = CustomEvent;
18-
};
15+
})();

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ npm install --save-dev jspolyfill-custom-event
1313
# Usage
1414

1515
```js
16-
require( 'jspolyfill-custom-event' )();
16+
require('jspolyfill-custom-event');
17+
```
18+
19+
or
20+
21+
```js
22+
import('jspolyfill-custom-event');
1723
```
1824

19-
**Note**: Make sure to add the extra set of parenthesis at the end to fire the `function` that
20-
registers the creation of the polyfill.
2125

2226
# Syntax
2327

0 commit comments

Comments
 (0)