Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Wrap whole lib in umd wrapper and remove redundant 'use strict' #270

Closed
wants to merge 1 commit into from

Conversation

jhnns
Copy link
Contributor

@jhnns jhnns commented Jun 20, 2014

This pull-request wraps the whole library in a umd wrapper.

It fixes a problem when fastclick is used with a bundler like browserify or webpack which use eval() for source urls.

According to the documentation on eval() in strict mode "strict" code can only access variables defined by eval() in the same scope. Thus accessing FastClick or deviceIsAndroid inside of a function (which is preceded by 'use strict';) triggers a ReferenceError.

Hence fastclick doesn't work with browserify or webpack in dev-mode.

The diff looks horrible because I needed to indent the whole lib. Actually I've done these changes:

  • Wrap the whole lib in a umd wrapper
  • Indent everything by one tab (accoding to your coding rules I guess)
  • Added 'use strict' at the beginning
  • Removed 'use strict' from every function

This also fixes #231

(function (root, factory) {
if (typeof exports === 'object') {
// CommonJS
module.exports = factory();
Copy link
Contributor

Choose a reason for hiding this comment

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

(Irritatingly) I think this should be:-

var FastClick = factory();
module.exports = FastClick.attach;
module.exports.FastClick = FastClick;

Otherwise we break the previous API expected by common js :-/

@jhnns jhnns closed this Aug 21, 2014
@jhnns jhnns deleted the add/umd branch August 21, 2014 13:02
jhnns added a commit to jhnns/fastclick that referenced this pull request Aug 21, 2014
It fixes a problem when fastclick is used with a bundler like browserify or webpack which
use eval() for source urls.

According to the documentation on eval() in strict mode "strict" code can only access
variables defined by eval() in the same scope. Thus accessing FastClick or deviceIsAndroid
inside of a function (which is preceded by 'use strict') triggers a ReferenceError.

ftlabs#270
jhnns added a commit to jhnns/fastclick that referenced this pull request Aug 21, 2014
It fixes a problem when fastclick is used with a bundler like browserify or webpack which
use eval() for source urls.

According to the documentation on eval() in strict mode "strict" code can only access
variables defined by eval() in the same scope. Thus accessing FastClick or deviceIsAndroid
inside of a function (which is preceded by 'use strict') triggers a ReferenceError.

ftlabs#270
jhnns added a commit to jhnns/fastclick that referenced this pull request Aug 21, 2014
It fixes a problem when fastclick is used with a bundler like browserify or webpack which
use eval() for source urls.

According to the documentation on eval() in strict mode "strict" code can only access
variables defined by eval() in the same scope. Thus accessing FastClick or deviceIsAndroid
inside of a function (which is preceded by 'use strict') triggers a ReferenceError.

ftlabs#270
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FastClick 1.0.0 defines globals outside of the FastClick namespace
2 participants