Hacker News new | ask | show | jobs
by ahoge 4152 days ago
"No framework"... so here is a framework. Uh hu.

Anyhow, move that "use strict;" line into the IIFE. If it's global, you can't merge that file with other files. Some of the code out there breaks in strict mode. That's why it isn't enabled by default.

1 comments

Well, it's a library, not a framework: you can use it for as much or as little of your app as you like with as little as a single attribute declaration doing something useful for you.

On "use strict", my understanding was that it applies per script:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Strict mode applies to entire scripts or to individual functions.

Am I misunderstanding?

Many sites have a build process that concatenates multiple JavaScript files into one. If they concatenate other scripts after yours, your "use strict" will apply to all of them.

Since the rest of your script is already enclosed inside a single function, simply move the "use strict" a few lines down so it is the first line in that function. Then it will only apply to your own code.

> Well, it's a library, not a framework: you can use it for as much or as little of your app as you like with as little as a single attribute declaration doing something useful for you.

If it has an entry point, it's not a library, it's an application. If said application does basically nothing on its own and you're supposed to extend it, it's a framework.

http://en.wikipedia.org/wiki/Software_framework

Pay close attention to the 4 bullet points in the first section.

> On "use strict", my understanding was that it applies per script

Yes. However, when you merge scripts, there is only one script at the end.

The site you linked to also mentions this problem.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

"This syntax has a trap that has already bitten a major site: it isn't possible to blindly concatenate non-conflicting scripts. [...] It is thus recommended that you enable strict mode on a function-by-function basis [...]"

Ah, OK. Well, good news: intercooler doesn't have an entry point.

Good point on the concatenation issue, I'll fix it for the next release.

> intercooler doesn't have an entry point.

It does.

There is an IIFE which is run when the script is loaded. Right before the object is returned to the global "Intercooler" variable, a callback is registered via a jQuery.ready() shorthand.

Practically speaking, this callback is the entry point (theoretically, it's the IIFE itself).

If it wouldn't have an entry point, adding attributes to elements would do nothing.

http://en.wikipedia.org/wiki/Entry_point

"an entry point is where control enters a program or piece of code"