Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

Add additional checking for angular source #195

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

qetr1ck-op
Copy link

In my case I load angular.js from cdn before import of the module.
So main point is that you need to have additional checking to require the angular source.

add additional checking to require `angular.js`
@qetr1ck-op
Copy link
Author

@douglasduteil
It would be great to merge this PR

@@ -1,6 +1,8 @@
//https://github.com/angular/angular.js/pull/10732

var angular = require('angular');
if (typeof angular !== 'undefined') {
Copy link

Choose a reason for hiding this comment

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

With variable hoisting the declaration of angular will be moved to the top of the file, which makes declare angular variable and set it to undefined. So the above condition fails, you need to have a different way to check whether angular is loaded or not

Copy link
Author

Choose a reason for hiding this comment

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

Where do you see to assigning it to undefined? It's only a conditional.
It's widely popular in npm comunity for AMD/UMD/CommonsJs/ES6module support.

Copy link

@bashasm bashasm Dec 7, 2016

Choose a reason for hiding this comment

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

I am referring to Variable hoisting
"Variable declarations, wherever they occur, are processed before any code is executed. The scope of a variable declared with var is its current execution context, which is either the enclosing function or, for variables declared outside any function"

MDN Reference https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/var

Please let me know if you think otherwise

Copy link
Author

Choose a reason for hiding this comment

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

Are you really aware what require() do?)
It doesn't execute anything, just returns an entity(function in our case)

Copy link
Author

Choose a reason for hiding this comment

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

And hoisting in this case would look like when interpretation be 3th line {...window.angular: undefined} or a function if it was required early.

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.

2 participants