Git Product home page Git Product logo

practice's Introduction

🎁 I just want to have more green squares on my contribution graph.

🎉 I knew it's not a really open source or project, but I will keep committing my practice code and taking my notes in issues.

🎊 I would be working hard to be a more professional Front-End Engineer.

practice's People

Contributors

karenchuang avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

practice's Issues

2018.4

4月

忙碌的面试月,换了一份工作 🍻

2018.5

5.23

cz-emoji

最近开始在新公司的项目里commit加emoji表情(手动打~
觉得这样好蠢,然后翻到这个cli工具~好好用
cz-cli
cz-emoji

image

内存溢出问题

image

node --max_old_space_size=4096

【深入浅出Nodejs】学习笔记

CommonJS 的模块规范

1. 模块引用

var math = require('math')

使用 require() 方法用于引入一个模块到当前上下文中。

2.模块定义

exports.add = function () {
    var sum = 0,
        i = 0,
        args = arguments,
        l = args.length
    while (i < l) {
        sum += args[i++]
    }
    return sum
}

模块中,存在一个module对象,它代表模块自身。

console.log(module)

output

Module {
  id: '.',
  exports: { add: [Function] },
  parent: null,
  filename: '/Users/karenz/Documents/github/practice/nodejs/add.js',
  loaded: false,
  children: [],
  paths:
   [ '/Users/karenz/Documents/github/practice/nodejs/node_modules',
     '/Users/karenz/Documents/github/practice/node_modules',
     '/Users/karenz/Documents/github/node_modules',
     '/Users/karenz/Documents/node_modules',
     '/Users/karenz/node_modules',
     '/Users/node_modules',
     '/node_modules' ] }

可见,exportmodule的属性
在 Node 中,一个文件就是一个模块。

4.模块标识

模块标识就是传递给require()方法的参数,它必须是符合小驼峰命名的字符串,或者以.、..开头的相对路径,或者绝对路径。

每个模块具有独立的空间

Node的模块实现

Node的模块分为2类

  1. 核心模块(node自身提供的)例如:http、fs、path
  2. 文件模块(用户编写的)

模块的加载

  1. 优先从缓存中进行加载。浏览器缓存的是文件,Node缓存的是编译和执行之后的对象。

2018.3

3.4

常用 ES6

数组和对象的解构写法

let { foo, bar } = { foo: "aaa", bar: "bbb" };

变量必须与属性同名,才能取到正确的值。

数组的扩展运算

数组的浅拷贝

const a1 = [1, 2];
// ES5
const a2 = a1.concat();
// ES6
const a2 = [...a1];
// or
const [...a2] = a1

Set

Set 结构不会添加重复的值

// 去除数组的重复成员
let array = [1,1,2,2,3]
[...new Set(array)]
  • add(value):添加某个值,返回 Set 结构本身。
  • delete(value):删除某个值,返回一个布尔值,表示删除是否成功。
  • has(value):返回一个布尔值,表示该值是否为Set的成员。
  • clear():清除所有成员,没有返回值。

Map

Symbol

ES6 引入了一种新的原始数据类型Symbol,表示独一无二的值。

前六种是:undefined、null、布尔值(Boolean)、字符串(String)、数值(Number)、对象(Object)。

let s = Symbol();

typeof s  // "symbol"

Symbol 值不能与其他类型的值进行运算,会报错。

Symbol 值可以显式转为字符串。

Iterator 迭代器

它是一种接口,为各种不同的数据结构提供统一的访问机制

作用:
  1. 为各种数据结构,提供一个统一的、简便的访问接口;
  2. 使得数据结构的成员能够按某种次序排列;
  3. ES6 创造了一种新的遍历命令for...of循环,Iterator 接口主要供for...of消费。
遍历过程

每一次调用 next 方法,都会返回数据结构的当前成员的信息。具体来说,就是返回一个包含value和done两个属性的对象。其中,value属性是当前成员的值,done属性是一个布尔值,表示遍历是否结束。

ES6 的有些数据结构原生具备 Iterator 接口(比如数组),即不用任何处理,就可以被for...of循环遍历。原因在于,这些数据结构原生部署了Symbol.iterator属性

for (let value of myArray) {
  console.log(value);
}

不同于forEach方法,它可以与break、continue和return配合使用。

供了遍历所有数据结构的统一操作接口。

for...in来遍历对象获得键值对
for...of来遍历数组等

2017.7

7.10

let

The let keyword allows the script to restrict access to the variable to the nearest enclosing block.

{
  let name = 'Karen';
}
console.log(name); //  name is not defined

var

The var keyword assigns a function scope to the variable.

var a = [];
for (var i = 0; i < 10; i++) {
  a[i] = function () {
    console.log(i);
  };
}
a[6](); // 10

const

Constants cannot be reassigned a value.
A constant cannot be re-declared.
A constant requires an initializer. This means constants must be initialized during its declaration.
The value assigned to a const variable is mutable. (??)

const KEY = 'abc';
KEY = 'one'; // Uncaught TypeError: Assignment to constant variable.

Template Literals

var name = "Karen"; 
console.log('Hello, ${name}!');  // Hello, Karen

or

Multiline Strings

var multiLine = `
   This is 
   a string 
   with multiple 
   lines`; 
console.log(multiLine)

Ref:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.