Skip to content

Instantly share code, notes, and snippets.

View ryanlid's full-sized avatar
🎯
Focusing

ryanlid ryanlid

🎯
Focusing
View GitHub Profile
@ryanlid
ryanlid / cloudSettings
Last active March 18, 2022 13:25
Visual Studio Code Sync Settings Gist
{"lastUpload":"2022-03-18T13:25:24.317Z","extensionVersion":"v3.4.3"}
@ryanlid
ryanlid / index.html
Created March 30, 2017 01:23
移动端 header
<!DOCTYPE html >
<html>
<head lang="zh-CN">
<meta charset="UTF-8">
<!-- 优先使用 IE 最新版本和 Chrome -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<!-- 为移动设备添加 viewport -->
<meta name="viewport" content="width=device-width,initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<!-- 添加到主屏后的标题(iOS 6 新增) -->
<meta name="apple-mobile-web-app-title" content="">
@ryanlid
ryanlid / throw.js
Created November 4, 2016 03:23
异常处理
var add = function (a, b) {
if (typeof a !== 'number' || typeof b !== 'number') {
throw{
name: 'TypeError',
message: 'add needs numbers'
};
}
return a + b;
};
@ryanlid
ryanlid / apply.js
Last active November 5, 2016 00:47
函数 Apply调用模式
// apply 方法让我们构建一个参数数组传递给调用函数。它也允许我们选择this的值,apply方法接收两个参数,第一个是要绑定给this的值,第2个是一个参数数组。
var add = function(a,b){
return a+b;
}
var array = [];
var sum =add.apply(null,array);
console.log(sum); // sum == 7
var add = function(a,b){
return a + b;
};
/* 方法调用模式 */
// 创建myObject,它有一个 value 属性和一个 increment 方法。
// increment方法接受一个可选的参数。如果参数不是数字,那么默认使用数字1。
var myObject = {
value :0,
increment:function(inc){
this.value +=typeof inc ==='number'? inc:1;
@ryanlid
ryanlid / webpack.config.js
Created October 28, 2016 05:38 — forked from learncodeacademy/webpack.config.js
Sample Basic Webpack Config
var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
module.exports = {
context: __dirname,
devtool: debug ? "inline-sourcemap" : null,
entry: "./js/scripts.js",
output: {
path: __dirname + "/js",
filename: "scripts.min.js"
@ryanlid
ryanlid / m.js
Created September 12, 2016 16:34
判断浏览器的 ua ,如果是移动端,链接跳转至子目录
(function () {
if (navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i)) {
location.href = 'm/index.html#type'
}
})();
@ryanlid
ryanlid / regexp.js
Created September 7, 2016 17:02
常用的正则表达式
// 验证是否为Email地址
function isPhoneNum(str) {
var pattern = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
if (pattern.test(str)) {
return true;
} else {
return false;
}
}
@ryanlid
ryanlid / .editorconfig
Last active May 2, 2017 11:19
EditorConfig是一套用于统一代码格式的解决方案
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true