During this time, I learned a little bit about ES6 's new specification, and then, on a whim, wanted to try the code written in ES6 to run in the browser.Say to do, first of all, the implementation of my steps (did not think there is a pit!) )
Translate the ES6 code into ES5;
HTML files are introduced into the ES5 after translation;
Then run in the browser environment;
Run in node environment;
Then here is some of my directory structure, a preview of a bit.SRC,ES6 Devel
functionfn1 () {5 6 }7 functionfn2 () {8 9 }Ten return { One fn1:fn1, Fn2:fn2 A }; -})();This approach is the basis of our JS modular, technology is endless, with the JS modular technology to improve, has produced different schools, branches; there are two main types: Commonjs and AMDTwo, CommonJS1. Define the module:According to the COMMONJS specification, a single file is a modul
still difficult to read.
③ Single threadNode is single-threaded. If it is multi-threaded, the language is too deep. It is annoying to ask a few words about the communication in the process, but there is no deadlock in the thread.However, there is a problem with performance, because multi-core cannot be used;
Module mechanism/CommonJs
We used to develop servers. If we didn't organize code well, it would be very difficult to maintain the code later, so
of WebpackIts advantages can be categorized as follows:1. Webpack is writing scripts in the form of CommonJS, but support for Amd/cmd is also comprehensive, facilitating code migration for older projects.2. It is not only JS that can be modularized.3. Easy to develop, can replace part of GRUNT/GULP work, such as packing, compression confusion, picture turn base64 etc.4. Strong extensibility, perfect plug-in mechanism, especially to support React hot
', comment.get); App.delete ('/comments/:id ', comment.delete); App.post ('/comments ', comment.add); App.put ('/comments/:id ', comment.update);Http.createserver (APP). Listen (App.get (' Port '), function () {console.log (' Express server listening on port ' + app.get (' Port '));Red parts are added to their own, the definition of additions and deletions to change the API interface. Code written in compliance with COMMONJS specifications3. Increa
I. modular specifications of js:
Server: commonjs
Browser end: AMD (abbreviation of "Asynchronous Module Definition", meaning "Asynchronous Module Definition ")Ii. Why AMD
The following code
var math = require('math'); math.add(2, 3);You must wait until the math. js loading is complete. Otherwise, the loading takes a long time.
Iii. define
Define (id ?, Dependencies ?, Factory );
Where:
Id: module id, which can be omitted.
Dependencies: the depe
passed-in component property Inittext value. Next we bind the onchange event in input, and when this event is triggered, we also modify the value of the State.text as the input control. In this way, the modification of the State.text is achieved, and the modification function of the interface display is achieved.Typescript at compile time we need to configure it, we add the Tsconfig.json file in the project root directory, add the following configuration code in the file:Let's take a general lo
The Commonjs loading module is synchronous, and the AMD module is added to the non-synchronous, allowing for the designation of the callback function. Since Nodejs is mainly used for server programming, module files are generally present in the local, so load quickly, do not need to consider the non-synchronous loading, with COMMONJS can. But the browser is loaded from the server module, which requires the
Node. js exports, module. exports, and ES6 export, export default in-depth explanation, node. jses6
Preface
Recently, it is rare to have time. I decided to learn node programming again in a standardized manner. However, the introduction module I see uses the require method, and I think of our ES6 various export and export default.
Axi, The heads are all big ....
When the head size is over, let's take a look at their scope of use.
Require: Introduction supported by node and es6
Export/import
, including front-end engineering and middle Tier.CSDN: as an example of a project you recently participated in, what is the front-end infrastructure like?Zhou Junpeng: take 58 Home Wallet homepage for example, This project belongs to the reconstruction project, the problem that needs to be solved includes: improve the homepage rendering speed, improve the user experience, solve the problem that the development cycle lengthens and the on-line process is not clear caused by the front and back end
First you can look at the official documents, the documentation is the best teacher. Here also has a foreign friend to write the introductory introduction.Webpack is an open source front-end module build tool developed by Tobias Koppers. Its basic function is to package multiple JavaScript files in a modular format into a single file, supporting both COMMONJS and AMD formats. But what makes it unique is that it provides a powerful loader API to define
introduced before the other JS files, so that our next solution is to solve the dependency relationship)Two. JS Module loaderThe new modular approach proposes that the problem of global variables and dependencies is resolved, but the performance aspect can also be optimized.The COMMONJS specification puts forward a new scheme to solve the problems of the global variable pollution and the complexity of the dependency relationship. (at first it runs on
After the ES6 standard is released, module becomes the standard, the standard use is to export the interface with export instruction, import into the module, but in our usual node module, we use the COMMONJS specification, using require to introduce the module, Export the interface using Module.exports. Node's module follows the COMMONJS specification, Requirejs follows the Amd,seajs follow the CMD, althoug
Most of the native configuration from Https://github.com/yanhaijing/fis3-base, the new part of the FIS3 to abandon the component for node_modules, removed some of their own not how to use the functionSet the project Properties Fis.set (' Project.name ', ' fis3-base '), Fis.set (' project.static ', '/static '), Fis.set (' Project.files ', [' *. html ', ' Map.json ', '/test/* ');//introduction of modular development plug-ins, set specifications for the COMMONJ
First CNPM install jquery, when jquery has been installed successfully, jquery can be used, but jquery is not global, and the path to introducing jquery,jquery in the components being used is jquery/dist/ Jquery.min.js,InPort $ from "jquery/dist/jquery.min.js" can be used for $;We can also configure it in Webpack.base.config.js; the alias of the path is easy to introduce:We can then introduce this in a component that uses jqueryImport $ from ' jquery 'Tip: In Webpack'soutput.libraryTarget,需要设置为v
CommonJS, defines a specification for a synchronous load script. For the browser side, because the JS script is at the far end, it is possible to block threads in a synchronous way for long periods of time. Therefore, the browser side of the JS loader is not strictly according to Commonjs to do. Seajs as an attempt to follow the COMMONJS specification of the load
Multi-Module dependencyJust for the example, we just ran through the webpack through the Entry.js portal file for packaging. Let's take a look at whether it really supports the COMMONJS and AMD two modular mechanisms. Let's create a few more JS files!Modify Module1.jsRequire (["./module3"], function () { console.log ("Hello webpack!");});Next fileModule2.js, using the COMMONJS mechanism to export the pac
I. Variable pollutionThe global variables and functions in JS are overwrittenTwo. node. JS SpecificationNode application is made up of modules, using the COMMONJS module specificationThree. COMMONJS specification1. Each file is a module with its own scope, defined in this file is private, other files are not visible2. Use the Require method to load other modules3. Within each module there is a module variab
Requirejs Getting StartedWith JavaScript in the development of a larger proportion of the need for a team to division, collaboration, for everyone's code can better use each other, this time the modular programming becomes an urgent need. But JavaScript itself is not a modular language. It doesn't support classes, let alone modules.Since the module is so important, the team development should be to develop a norm, to constrain everyone, so that it is easy for everyone to use each other. If every
the modular specification of JS:
Server side: Commonjs
Browser side: AMD ("Asynchronous module definition" abbreviation, meaning "asynchronous modules defined") second, why the use of AMD
The following code
var math = require (' math ');
Math.add (2, 3);You must wait for the math.js load to complete, otherwise the load time will appear very long phenomenon
Third, define
define (ID, dependencies, factory);
Where: ID: module identification, can be o
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.