("I'm subPageB");export default "subPageB";
Note: Statements are executed in both Subpagea.js and subpageb.js two files console.log() . Then you will see import() and require() different forms of expression: Will the JS code be executed automatically?2. Writing the configuration file
Write the following webpack configuration file (very simple):
const webpack = require("webpack");const path = require("path");module.exports = { entry: { page: "./src/page.js" // }, output: { publicPath: __
than the call to Foo. The essence of this behavior is that the import command is executed at compile time, before the code runs.
Because import is static execution, expressions and variables cannot be used, which can only get the syntax structure of the result at run time.
Error
Import {' F ' + ' oo '} from ' My_module ';
Error let
module = ' My_module ';
Import {foo} from module;
Error
if (x = = 1) {
import {foo} from ' Module1 ';
} else {
import {foo} from ' Module2 ';
}
The above thre
Problem one: The introduction of front-end libraries, the method is not the sameFor example Lodash.js, as a chunk with html-webpack-plugin packaging to the page, will generate a global variable window._, in other JS do not have to require (' Lodash '); You can use Window._ directly.such as Webpack-zepto, as a chunk with html-webpack-plugin packaging to the page, will not generate window.$, if in other JS directly use window.$, will error. Need var $ =
Jest Installation
Install the jest command line by using the command NPM installation jest-cli--save-dev:
Localhost:testerhome wuxian$ npm Install jest-cli--save-dev jest-cli@0.7.1 node_modules/jest-cli├──jasmine-pit@2.0.2 ├──object-assign@4.0.1├──graceful-fs@4.1.2├──through@2.3.8├──resolve@1.1.6├──diff@2.2.0├──optimist@0.6.1 (WORDW rap@0.0.3, minimist@0.0.10) ├──json-stable-stringify@1.0.0 (jsonify@0.0.0) ├──mkdirp@0.5.1 (minimist@0.0.8) ├── which@1.2.0 (is-absolute@0.1.7) ├──worker-farm@1.3.1
One pattern in functional programming is to implement a combination function by combining functions of multiple functions. A tool library that generally supports functional programming implements this pattern, which is commonly referred to as compose and pipe. For example, the Ramda tool Library, known as the functional type.
const R = require('ramda');function inc (num) { return ++num;}const fun1 = R.com
Data filtering is not complicated. You only need to clarify your ideas and understand what data needs to be retained and what data is temporary (intermediate process, what data is the final result ...... Using the related methods in Array. prototype, or tools such as lodash, it is easy to process them. All codes use ES2015 syntax. If ES5 syntax is required, you can use Babel-Try it out or TypeScript Playground for translation.
Problem proposal
Today,
, expectedActions, done) store.dispatch(action)})
For more in-depth redux testing, see the official documentation.
Use npm
Although React. js does not rely on code building tools, we recommend Webpack and Browserify, both of which have excellent npm capabilities. Npm has many React. js packages and can help you manage dependencies elegantly.
(Do not forget to reuse your own components. This is an excellent way to optimize the code .)
Bundle size)
This is not a React-related issue, but mos
For example, Lodash supports the partial introduction of:Import IsArray from ' Lodash/isarray ';Reference: [Don ' t import whole Lodash] (https://github.com/lodash/lodash/issues/3450)When this optimization method is carried out, the chunk volume and content can be anal
there are many flaws, it is difficult to see1. Both the index.js and print.js files are introduced Lodash, and the repeating Lodash module is loaded two times2. It is inflexible and cannot dynamically separate business and core applicationsNow we need to extract the public Lodash module. Then we can use the Splitchunksplugin plugin.2. Prevention of duplication,
by for...in. for(Let keyinchobj) {Cloneobj[key]= IsObject (Obj[key])?Deepclone (Obj[key]): Obj[key]}returnCloneobj}let Result=deepclone (test) Console.log (result) for(Let keyinchresult) { if(IsObject (Result[key])) Console.log (' ${key} the same? ', Result[key]===Test[key])}//We found that both arr and obj were successfully copied, their memory references were different, but Func, date, Reg, and err did not succeed because they had special constructors. Deep Copy Method 4: Iterative re
Currying is a core concept of functional programming and a useful tool for any developer ' s toolbelt.Example 1:Let F = a = b = + c =a+b+ = f (1) (2) (3// 6Example 2:DOCTYPE HTML>HTML>Head> MetaCharSet= "Utf-8"> title>JS Bintitle> Scriptsrc= "Https://cdnjs.cloudflare.com/ajax/libs/ramda/0.18.0/ramda.min.js">Script>Head>Body>DivID= "One"style= "width:100px;height:100px;border:2px solid black">OneDiv>DivID= "both"style= "width:100px;height:100px;bor
We can dot-chain our The great success with a instance of maybe, but there is probably cases where you need to apply The same series of transformations against different Maybe s. In this lesson, we'll look at some point-free versions of some common maybe methods and see how we can compose them togeth Er to get a reusable function, can applied to any maybe instance.We is going to rewrite the following code by using function Composion:ConstCrocks = require ('crocks')Const{and, compose, IsEmpty, is
-- indeed, this is a feature of HashMap and is unordered. However, the results are the same no matter who is the first. However, some compound conditions may be affected.
If necessary, we can use array instead of map to solve the order problem, but this will reduce the search efficiency (linear search ). If you want to solve the search efficiency problem, you can use array + map to handle it. I will not talk about it here.
Filter
In fact, when using getFilter (), it is really slow to use a loop
version: v1.11.3 or v2.1.4Official website: jquery.comUnderscore and LodashSometimes built-in JavaScript is not enough to make programmers really productive. There is always a lack of a tool function, or a function that simplifies the code. Underscore (and Lodash) is a JavaScript library that provides a complete set of tool functions that require less experienced programmers to patch the built-in JavaScript objects. The two libraries provide more tha
Summary of various issues:1, unable to resolve modules Lodash (Here's an example Lodash, this lodash can be anything else.) This means that the current module is missing, so it needs to be installed)NPM Install Lodash--saveor (make version of the command): NPM install [email protected]2. [Email protected] should be ins
package.json the main field (you can have webpack check the Bower field at the same time), or if there is no package.json main field, it will be used index as the file name. After the above procedure, we resolve to an absolute path of the file name, and then try to add the extension (the extension can be webpack.config.js set in), the first existing file as the final result.
Relative paths, such as require(‘./file‘) . Use the current path or directory as a relative path in the configuration
Chaining calls we usually use a lot, such as $ (ele) in jquery. Show (). Find (), hide (), and so on, such as $http.get (URL) in Angularjs. Success (fn_s). Error (Fn_e). But this is already packaged chain call, we can only realize the convenience of chain call, but do not know how to form such a function chain principle is what.With the popularity of chained calls, more and more programs are implemented. The most common is the way that jquery returns this directly, underscore in an optional way,
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.