Skip to content
Akin C edited this page Apr 15, 2018 · 6 revisions

Welcome to the Javascript-wrapping-strict-mode- wiki!

This repository is part of a larger project!

◀️ PREVIOUS PROJECT| NEXT PROJECT ▶️


The project "Javascript-concatenating-strict-files-" explains the difficulty in strict mode when concatenating two js files. Based on that knowledge wrapping the body of more than one js file is an option to overcome the difficulty.

For the sake of completeness there will be aspects which can also be found in "Javascript-concatenating-strict-files- wiki".

Wrapping

Wrapping is a synonym for engulfing something. In this project the code of every file is engulfed in a function as follows:

//Wrapping the function into a function
(function()
{
	function a_function_name()
	{
		//body
	}

	//function call by name
	a_function_name();
})();

The first function is calling automatically itself by the last parenthesis.

Initial condition

The content of two files were merged into one file with the help of gulp. These files are "no strict.js" and "strict.js".

Gulp is a toolkit for automating time consuming processes in developement. There are very well made tutorials based on grunt and gulp. Here are some recommendable on youtube by Tech CBT:

  1. Grunt JS: Quick Introduction
  2. Gulp JS: Quick Introduction (in 30 min)

In the file "README_TO_GULP.txt" is a quick explanation how to install and use gulp for this project.

To concatenate the two files "no strict.js" and "strict.js", a file "gulpfile.js" is needed which can be downloaded from the code section of this github project. If not interested, there is no need to make all the work, because "example1" and "example2" contain already the results.

"example1"

This contains the concatenated js code in the following sequence.

  • first - "no strict.js"
  • second - "strict.js"

"example2"

This contains the concatenated js code in the following sequence.

  • first - "strict.js"
  • second - "no strict.js"

Result

"example1" and "example2" show no concatenated trouble with the strict mode. They work both as they should!

Clone this wiki locally