• Boolean && 变量
  • Boolean || 变量可以用来设置默认值
  • a.indexOf(b)a为字符串或者数组
  • a.toFixed(2)a类型为number,保留小数
  • toString()可以判断对象的类型。Object.prototype.toString.call(<value>)
  • -a可以将a转化为number类型
  • 正则表达式//gi,g表示全局搜索,i表示忽略大小写
  • js不支持负向零宽断言/(?<=Jack)Sprat/(ES2018后支持)
  • Math.floor()向下取整,Math.ceil()向上取整,Math.round()四舍五入。
  • arr.sort()如果 a 小于 b,返回值为负数,如果 a 大于 b,返回值为正数。
  • substr() 方法返回一个字符串中从指定位置开始到指定字符数的字符。
    不改变原数组,字符串
    str.substr(start[, length])
  • Array.prototype.slice()
    String.prototype.slice()
    slice() 方法返回一个新的数组对象,这一对象是一个由 begin 和 end 决定的原数组的浅拷贝(包括 begin,不包括end)。原始数组不会被改变。
  • Array.prototype.splice(start[, deleteCount[, item1[, item2[, ...]]]])
    splice() 方法通过删除现有元素或者原地添加新的元素来修改数组,并以数组形式返回删除的元素。此方法会改变原数组。
  • Array.forEach(arguments, func())对非数组序列进行forEach处理
  • Array(<len>).fill(<value>) 填满数组
  • 数组操作: shift(),unshift(),pop(),push()。改变原数组。
  • this总是指向函数的直接调用者(而非间接调用者),在DOM事件中,this指向定义这个事件的DOM对象;
  • t=setTimeout(fun(), N毫秒);clearTimeout(t)t=setInterval();clearInterval(t)
  • async与await
1
2
3
4
5
6
var start = async function () {
for (var i = 1; i <= 10; i++) {
console.log(`当前是第${i}次等待..`);
await sleep(1000);
}
};
  • e.preventDefault();
  • e.stopPropagation()阻止捕获和冒泡阶段中当前事件的进一步传播

对象处理

  • Object.keys(obj)得到对象的可枚举属性
  • delete Obj.prop删除对象属性
  • 字符串与对象的转换:JSON.stringify(json)JSON.parse(string)。Array也是Object类型
  • 字符串变量d用作对象属性名:{ [d]: !this.state[d] }

作用域

  • if块级作用域在ES5与ES6中不同
  • const a = func; 与function a(){}的变量提升方式不同;
  • for循环中let 与var i = 0,在函数中不同

原型继承

  • 对象的constructor属性指向它的构造函数。对象的__proto__属性指向上一级的原型对象。构造函数的prototype等于其生成对象的getPrototypeOf(__proto__)。
  • 必须显式地设置原型才能确保动态的继承,将B设置为A的原型链: A.prototype = new B;
  • 将构造器B属性传给A作为A的自身属性
1
2
3
4
function A (a, b) {
B.call(this, c, d);
this.machine = mach || "";
}
  • A为函数:A.prototype={ constructor: A, __proto__: 基本prop }

Web APIs

  • 在chrome中加入断点:在源码中加入debugger
  • 前端全局对象window,node.js全局对象global。全局对象可以用来设置全局变量window.abc
  • window.location获取当前页面网址信息,可进行页面跳转
  • fetch跨域加上{ mode: ‘no-cors’ },response类型为opaque,status为0。或者使用fetch-jsonp
  • 赋值localStorage.abc = string,数字存入localStorage后变为string
  • URLSearchParams
  • es6 array新方法

样式

  • border: 5px solid red;
  • margin: top left-right bottom;
  • display:inline-block;
  • cursor: point;
  • 设置边框阴影box-shadow: inset 0 0 2em blue;
  • 图文并排
1
2
3
4
5
.dom {
background:url('/images.jpg') no-repeat;
padding-left:
width:
}
  • inline元素设置高度: {display: inline-block;}再设置 width height
  • a {color: #000;} * 未被访问的链接 *
  • a:visited {color: #3ac1bd;} * 已被访问的链接 *
  • a:hover {color: #3ac1bd;} * 鼠标指针移动到链接上 *
  • a:active {color: #3ac1bd;}
  • a{ text-decoration: none; } 去掉链接的下划线

排版

  • position: relative - absolute;
  • 填满整个元素:父元素设置高度,子元素height: 100%
  • css度量运算calc(100% - 36px)
  • hover显示新元素
1
2
3
4
<parent>
<child1/>
<child2/>
</parent>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
.parent {
position: relative;
.child1, .child2 {
height: 100px;
width: 100px;
}
.child2 {
display: none;
background: rgba(230, 230, 230, 0.9);
}
}
.parent:hover .child2 {
display: block;
position: absolute;
top: 0;
cursor: pointer;
}

对齐

  • margin: auto;

  • 水平对齐

    父元素中设置text-align: left | right | center | justify | inherit;

  • 垂直对齐:

    子元素为inline,table-cell或者inline-block时vertical-align: top | text-top | middle | bottom | text-bottom;table-cell与inline-block中middle显示不同

    block元素中的文字line-height设置为该元素height

Flex

  • 子元素的float、clear和vertical-align属性将失效。
  • flex-direction: row | row-reverse | column | column-reverse;
  • flex-flow: flex-direction | flex-wrap;
  • justify-content: flex-start | flex-end | center 水平对齐方式
  • align-items: flex-start | flex-end | center 垂直对齐方式
  • 多根轴线align-content: flex-start | flex-end | center | space-between | space-around | stretch;
  • 保留空白符white-space: normal|pre|nowrap|pre-wrap|pre-line|inherit;

Css单位

  • vh:屏幕比例。px:像素。rem根元素的字体大小

Css选择器

  • .class #id element
  • 直接子元素:>
  • 选择器之间,表示and

进入项目文件根目录

git init将该文件夹加入git的管理之中, 并新建了一个.git/文件夹

新建.gitignore文件让git忽略不需要同步的文件夹/文件。

git add ..目录——就是当前目录加入git暂存区域(staging area)。

git commit -m "first commit"将声明区的文件加入到本地仓库

git remote add origin git@github.com:ABCD.git添加远程仓库的路径,并命名为origin,git@ABCD.git为使用ssh协议同步,https://ABCD.git使用https协议同步。ssh同步需用额外的配置,但是之后不需要输入密码,而且安全性更高。https协议需要每次输入用户名和密码,想要省略输入密码,就需要明文保存在本地电脑上,安全性低。

git push -u origin master将本地仓库推送到名为origin的远程仓库的master分支(branch)

创建博客,记录一些事,可能以后用得着。

0%