Movatterモバイル変換


[0]ホーム

URL:


codecamp

Atom JS 代码片段补全

JS 代码片段补全

题外话

这款插件就比较重量级了,用熟悉了写原生 JS 的效率要提升很多。而且,不仅支持 JS 还包含了 nodejs snippet。

javascript-snippets

插件作者: zenorocha

Github地址 :https://github.com/zenorocha/atom-javascript-snippets

内置了丰富的 JS snippet。而且也很好理解和记忆,耍多了会上手的。

安装

  • 在设置中心搜索安装

代码片段(Tab 或者 Enter 补全)

Console 命令

[cd] console.dir — 这条命令可以遍历一个对象内容

console.dir(${1:obj});

[ce] console.error — 打印出信息带有错误图标

console.error(${1:obj});

[cl] console.log — 打印出信息

console.log(${1:obj});

[cw] console.warn — 打印带有警告图标的信息

console.warn(${1:obj});

DOM — 文档对象模型

[ae] addEventListener — 事件监听

${1:document}.addEventListener('${2:event}', function(e) {    ${0:// body...}});

[ac] appendChild — 增加子元素

${1:document}.appendChild(${2:elem});

[rc] removeChild — 删除子元素

${1:document}.removeChild(${2:elem});

[cel] createElement — 创建元素

${1:document}.createElement(${2:elem});

[cdf] createDocumentFragment — 创建文档碎片节点

${1:document}.createDocumentFragment(${2:elem});

[ca] classList.add — 冷门属性,为了解决 className 不能解决出现,没用过

${1:document}.classList.add('${2:class}');

[ct] classList.toggle — 同上

${1:document}.classList.toggle('${2:class}');

[cr] classList.remove — 同上

${1:document}.classList.remove('${2:class}');

[gi] getElementById — 获取元素ID

${1:document}.getElementById('${2:id}');

[gc] getElementsByClassName — 获取元素类名[返回值为数组]

${1:document}.getElementsByClassName('${2:class}');

[gt] getElementsByTagName — 获取标签集合[返回值是一个nodeList,非数组]

${1:document}.getElementsByTagName('${2:tag}');

[ga] getAttribute — 获取属性值

${1:document}.getAttribute('${2:attr}');

[sa] setAttribute — 设置属性值

${1:document}.setAttribute('${2:attr}', ${3:value});

[ra] removeAttribute — 移除属性值

${1:document}.removeAttribute('${2:attr}');

[ih] innerHTML — 代码块插入 html 结构

${1:document}.innerHTML = '${2:elem}';

[tc] textContent — 纯文本,裸奔的 innerHTML

${1:document}.textContent = '${2:content}';

[qs] querySelector — HTML5 新属性,获取选择器,类似 JQ 的$(‘div#name’)

${1:document}.querySelector('${2:selector}');

[qsa] querySelectorAll — 同上,都支持多个选择器,但这个返回一个 nodeList

${1:document}.querySelectorAll('${2:selector}');

Loop

[fe] forEach — 遍历数组或者对象用的方法

${1:myArray}.forEach(function(${2:elem}) {    ${0:// body...}});

[fi] for in — 遍历对象用的方法

for (${1:prop} in ${2:obj}) {    if (${2:obj}.hasOwnProperty(${1:prop})) {        ${0:// body...}    }}

Function

[fn] function — 函数声明

function ${1:methodName} (${2:arguments}) {    ${0:// body...}}

[afn] anonymous function —- 匿名函数

function(${1:arguments}) {    ${0:// body...}}

[pr] prototype — 原型

${1:ClassName}.prototype.${2:methodName} = function(${3:arguments}) {    ${0:// body...}}

[iife] immediately-invoked function expression — 函数表达式

(function(window, document, undefined) {    ${0:// body...}})(window, document);

[call] function call — 回调函数

${1:methodName}.call(${2:context}, ${3:arguments})

[apply] function apply — 回调函数

${1:methodName}.apply(${2:context}, [${3:arguments}])

[ofn] function as a property of an object — 函数声明

${1:functionName}: function(${2:arguments}) {    ${3:// body...}}

Timer

[si] setInterval — 根据设置时间不断调用的方法

setInterval(function() {    ${0:// body...}}, ${1:delay});

[st] setTimeout — 同上,区别在于一般不会重复执行

setTimeout(function() {    ${0:// body...}}, ${1:delay});

NodeJS

[ase] assert.equal

assert.equal(${1:actual}, ${2:expected});

[asd] assert.deepEqual

assert.deepEqual(${1:actual}, ${2:expected});

[asn] assert.notEqual

assert.notEqual(${1:actual}, ${2:expected});

[me] module.exports

module.exports = ${1:name};

[pe] process.exit

process.exit(${1:code});

[re] require — 请求模块

require('${1:module}');

BDD

[desc] describe

describe('${1:description}', function() {    ${0:// body...}});

[ita] it asynchronous

it('${1:description}', function(done) {    ${0:// body...}});

[its] it synchronous

it('${1:description}', function() {    ${0:// body...}});

[itp] it pending

it('${1:description}');

Misc

[us] use strict — JS语法使用严格模式

'use strict';

[al] alert — 弹窗

alert('${1:msg}');

[pm] prompt — 提示弹窗

prompt('${1:msg}');
Atom JQ 代码片段补全
Atom 深入自定义快捷键
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录
Atom 简介
Atom 基础
Atom 插件主题推荐
Atom 自定义按键绑定
Atom 保存与预览功能
Atom config.cson 基础教程
Atom Emmet 实例教程
Atom 分屏操作
Atom 实用侧边栏插件
Atom CSScomb 增强版
Atom 编辑器实时预览 HTML 页面
Atom Sync-setttings(插件-备份神器)
Atom JS 代码智能提示补全
Atom JQ 代码片段补全
Atom JS 代码片段补全
Atom 深入自定义快捷键
Atom atom-minify(CSS/JS压缩神器)
Atom Atom 内运行 gulp 的实现方法
Atom Atom 代码输入震动效果

ATOM版本更新

关闭

MIP.setData({'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false},'pageFontSize' : getCookie('pageFontSize') || 20});MIP.watch('pageTheme', function(newValue){setCookie('pageTheme', JSON.stringify(newValue))});MIP.watch('pageFontSize', function(newValue){setCookie('pageFontSize', newValue)});function setCookie(name, value){var days = 1;var exp = new Date();exp.setTime(exp.getTime() + days*24*60*60*1000);document.cookie = name + '=' + value + ';expires=' + exp.toUTCString();}function getCookie(name){var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)');return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null;}
[8]ページ先頭

©2009-2025 Movatter.jp