Skip to content

Instantly share code, notes, and snippets.

View yorickshan's full-sized avatar
🎯
Focusing

Shan Yinlong yorickshan

🎯
Focusing
View GitHub Profile

忽略 var 声明

可以正常运行的代码并不代表是合适的代码

在严格模式中,为未声明的标识符赋值将会抛引用错误,可以防止意外的全局变量属性的创建

"use strict"
a = 1 // -> Uncaught ReferenceError: a is not defined; 此处直接报错
@yorickshan
yorickshan / js43.md
Last active August 9, 2019 07:32
for in Object.prototype.hasOwnProperty() Object.prototype.isPrototypeOf() Object.prototype.getOwnPropertyNames() Object.prototype.keys() Object.getOwnPropertySymbol() JSON.stringify()

Object.prototype.hasOwnProperty

检测一个对象是否含有特定的自身属性

o = new Object();
o.prop = 'exists';
o.hasOwnProperty('prop');             // 返回 true
o.hasOwnProperty('toString');         // 返回 false
o.hasOwnProperty('hasOwnProperty'); // 返回 false

伪类

The pseudo-class concept is introduced to permit selection based on information that lies outside of the document tree or that cannot be expressed using the other simple selectors.

伪元素

Pseudo-elements create abstractions about the document tree beyond those specified by the document language. For instance, document languages do not offer mechanisms to access the first letter or first line of an element's content. Pseudo-elements allow authors to refer to this otherwise inaccessible information. Pseudo-elements may also provide authors a way to refer to content that does not exist in the source document (e.g., the ::before and ::after pseudo-elements give access to generated content).

浅谈CSS中的伪元素和伪类

死链接 href="javascript:void(0);"

目的: 保留链接的样式,但不执行实际操作

<a href="javascript:void(0)">单击此处什么也不会发生</a>
// javascript:
@yorickshan
yorickshan / html7.md
Last active June 16, 2019 13:40
兼备高语义和高易用性
  • 抛弃table布局
  • 使用label标签并和输入控件关联
    // 方式1 利用for属性
    <input type="checkbox" id="keepSigned" name="keepSigned" value="" />
    <label for="keepSigned">Keep Me Signed.</label>
    
    // 方式2 将输入控件作为label的子元素
    <label>
      <input type="checkbox" id="keepSigned" name="keepSigned" value="" />

一、利用ES6 Set去重(ES6中最常用)

function unique (arr) {
  return Array.from(new Set(arr)); // 或着利用扩展运算符 return [...new Set(arr)];
}
var arr = [1,1,'true','true',true,true,15,15,false,false, undefined,undefined, null,null, NaN, NaN,'NaN', 0, 0, 'a', 'a',{},{}];
console.log(unique(arr))
//[1, "true", true, 15, false, undefined, null, NaN, "NaN", 0, "a", {}, {}]
@yorickshan
yorickshan / css32.md
Created June 5, 2019 02:16
@media 可以针对不同的屏幕尺寸设置不同的样式,设置设计响应式的页面 在重置浏览器大小的过程中,页面也会根据浏览器的宽度和高度重新渲染页面

_

JSON.stringify([1,2,3].sort()) === JSON.stringify([3,2,1].sort()); //true

或者

[1,2,3].sort().toString() === [3,2,1].sort().toString(); //true