Learning full-stack Javascript MongoDB, react and node

Arrow func this 

node - index.js 

exports.i = 'am exports'
console.log(this); // {i: 'am exports'}

let util = {
    f1: function() {
        console.log(this);
    },
    
    f2: () => {
        console.log(this);
    }
}

util.f1(); // {f1: ƒ, f2: ƒ}
util.f2(); // index.js:10 {i: "am exports"}

Arrow functions, beside being shorter and more fun to type, are lexically scoped, which is a fancy way of saying that they close over the this keyword available on their parent, while regular functions use the caller to determine what's inside their this keyword. For example, in a Node module, the top level, this keyword, is the exports object, which is empty by default.I'm adding a property i here just to identify it. In here, I have a util object, which defines two functions.

F1 is regular scope, f2 is arrow scope. When we normally call f1, the this keyword in f1 will be the caller, which is the util object, while the this keyword in f2 will be the parent scope, which is the exports object.

 

const Component = require('react').Component

const {Component} = require('react').Component

import react, {Component} from 'react' 

 

Beginning project from scratch (with only Readme.md, LICENSE, .git, .gitignore from github):

1. npm installation

npm init (generate package.json)

Main dependency:

npm i express (create a node server)

npm i mongodb (connect to database)

npm i react react-dom (react: user interface, react-dom: render interface)

npm i prop-types

Dev dependency:

npm i -D webpack webpack-cli (translate modular code into something the browser can understand. webpack: library,

webpack-cli: cmd interface)

npm i -D babel-loader @babel/node @babel/core @babel/preset-env @babel/preset-react @babel/plugin-proposal-class-properties

( Now, Wepback itself is just the bundler.We still need to configure it with loaders to transform the JFX extension code into what React understands today. That loader is Babel. Babel will also transform a few of the modern JavaScript features that are not yet supported natively in all browsers.)

npm install -D nodemo (Now, when we make changes in a Node project, a restart is required for the changes to be reflected in any running process, but instead of manually restarting Node, let's bring in the nodemon package. npm install -D nodemon. This package can monitor our files and autorestart Node for us when we save changes to this)

npm i -D eslint babel-eslint eslint-plugin-react (eslint configuration lacks!)

2.configurations

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值