Node.js Development Guide - Book Notes

Chapter 3

  1. Single Loading:

    require does not load modules repeatedly. No matter how many times require is called, the module obtained is always the same one.

  2. Overriding exports:

    When encapsulating an object into a module, using exports.Hello = Hello requires require(‘./singleobject’).Hello to obtain the object. This can be simplified as follows: module.exports = Hello; Then you can directly obtain the object: var Hello = require(‘./hello’); hello = new Hello();

  3. Creating Global Links:

    npm link express; This allows you to use the globally installed express in the current directory.

  4. Use npm init to interactively initialize a standard package.json;
    Publish a package: npm publish;
    After modifying the version field in the json file, republish to update the version;
    Unpublish: npm unpublish;

Read more

Internship Summary

Continuing from “Don’t Call Me a Programmer, I’m a Front-End Development Engineer” – so I went to Wacai for my internship, fast forward through ten thousand words, and I successfully converted to a full-time position, then returned to school to write my graduation thesis.

Read more

From line-height to 0.5px

A few days ago, I noticed a piece of code where the line-height (1.7rem) equaled the height (1.7rem), and the font-size was 1.1rem. On iOS devices, the text was vertically centered, but on Android devices, the top and bottom gaps differed by 1px (I couldn’t actually tell if it was exactly one pixel – I was guessing).

Read more

Schema and Download Bar

Since our company had a website without a corresponding mobile version, we needed to display a download bar at the bottom when the website is accessed from a mobile device. Clicking the download bar needed to meet the following two requirements:

  1. If the app is already installed on the device, attempt to open the corresponding app;
  2. If the app is not installed on the device, redirect to the download page for the corresponding operating system.
Read more

HTML5 Screenshot

Implement a QQ-screenshot-like tool: click the load button to load an image, long-press on the image to bring up a cropping box, resize the cropping box from its bottom-right corner, and display a real-time preview in the preview area on the right.

Read more

16-Grid Drag and Drop

Implement a 16-grid page as shown below, where each numbered box can be dragged and swapped with another. The horizontal and vertical header bars ABC and XYZ allow pairwise swapping of positions, causing entire columns (or rows) to swap together.

Read more

Notes on JavaScript: The Definitive Guide

  1. When the JavaScript interpreter starts, it creates a new global object and gives it a set of defined initial properties.
  2. Whenever a property of a string literal is referenced, the string value is converted to an object by calling new String(), and once the reference ends, this temporary object is destroyed.
  3. The “==” operator treats primitive values and their wrapper objects as equal, while “===” does not.
  4. Primitive values are immutable; object references are mutable.
  5. undefined converted to number:

    NaN, while null converted to number: 0, empty string converts to 0 and false.

Read more

Don't Call Me a Programmer, I'm a Front-End Engineer

I first discovered front-end development toward the end of last semester. At the time, I was busy running experiments, writing papers, and submitting articles, so I didn’t dive deep into it. I thought it was quite fun, so I eagerly went and borrowed a copy of HTML and CSS: A Beginner’s Guide. I was so confused back then. At first, I had borrowed Thinking in Java and Android 4.X: From Beginner to Expert, planning to brush up on Java and then try writing some Android apps before graduating into Android development – but I never followed through. The beginner’s guide was very basic and easy to read, and my interest gradually grew.

Read more