Tag: Refactoring
-
Post Views: 32 1. Search in Githab: mocha, select the first one: mochajs/mocha, a simple, flexible and interesting JavaScript test framework for node.js and browsers. as shown in Figure 1 2. Click the link documentation to enterhttps://mochajs.org/ 3. Reference installation:https://mochajs.org/#installation, as a project development dependency, use npm to install, enter the project directory: npm install –save-dev mocha. as shown in…
-
Post Views: 17 1. Reference: In Refactoring: Improved Design of Existing Code (2nd Edition), build the test system – the writing of the sample code to be tested:https://www.shuijingwanwq.com/2023/01/28/7368/. The problem now is that multiple classes exist in the same file. Decided to split, each class forms a separate file. 2. Create a new class file /modules/producer.js, and migrate the class…
-
Post Views: 17 1. A code to be tested. This code comes from a simple application that supports users to view and adjust production plans. Its (slightly rough) interface looks like the picture below. as shown in Figure 1 2. The final implementation of the example code is as follows, the productionplan.html file code of the entrance is as follows…
-
Post Views: 19 1. UncaughtXError: Cannot use import statement outside a module (at statement.js:1:1). Reference: Refactoring: Improve the design of existing code (2nd edition). as shown in Figure 1 2. The code is implemented as follows, as shown in Figure 2 statement.html statement.js CreateStatementData.js 3. Reference:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/Modules. JavaScript module. You need to put type=”module” into the script tag to declare that…
-
Post Views: 19 1. When learning to refactor: improve the design of the existing code (2nd edition), it is found that the function statement is missing 1 } at the end, which leads to the problem of the code format display. as shown in Figure 1 2. I have always mistakenly thought that the code itself was omitted }, so…
-
Post Views: 20 1. The existing implementation is as follows 2. Reference 10.1 Decompose conditional expression (decompose conditional), adjust to the following 3. 10.2 Consolidate conditional expression (Consolidate conditional expression). Extracting the inspection conditions into a separate function is very useful for clarifying the meaning of the code, because it replaces the statement describing “what to do” with “why do…
-
Post Views: 17 1. The troupe stores the data of the play in a simple JSON file. 2. The bills they issued are also stored in a JSON file. 3. The following simple function is used to print the details of the bill. 4. Use the above data files (invoices.json and plays.json) as test input, run this code, you will…
-
Post Views: 20 1. Check the existing implementation code as follows: 2. Check the print results before and after the multidimensional array index. Use the value of the name column in the array as the new key. as shown in Figure 1 3. However, just using the function array_column is enough to achieve. When column_key is null, the entire array…