#turbo-javascript-YAS A collection of snippets for optimizing Javascript development productivity in Emacs using YASnippet, ported in large part from turbo-javascript, with additions, omissions, and changes detailed below:
Quickly log things to the console
console.log($0);
console.error($0);
console.warn($0);
Fast expansion for common flow control statements
if (${1:condition}) {
$0
}
else {
$0
}
else if (${1:condition}) {
$0
}
for (var ${1:i} = 0, ${2:len} = ${3:iterable}.length; ${1:i} < ${2:len}; ${1:i}++) {
$0
});
for (var ${1:key} in ${2:source}) {
if (${2:source}.hasOwnProperty(${1:key})) {
$0
}
}
while (${1:condition}) {
$0
}
Declare and manipulate functions with ease
function (${1:arguments}) {$0}
function ${1:name} (${2:arguments}) {
$0
}
(function (${1:arguments}) {
$0
})(${2});
${1:fn}.apply(${2:this}, ${3:arguments})
${1:fn}.call(${2:this}, ${3:arguments})
${1:fn}.bind(${2:this}, ${3:arguments})
${1:iterable}.forEach(function (${2:item}) {
$0
})
${1:iterable}.map(function (${2:item}) {
$0
})
${1:iterable}.reduce(function (${2:previous}, ${3:current}) {
$0
}${4:, initial})
${1:iterable}.filter(function (${2:item}) {
$0
})
Shortcuts for dealing with types, objects, classes and inheritance.
${1:key}: ${2:'value'}$0
${1:Class}.prototype.${2:methodName} = function (${3:arguments}) {
$0
}
typeof ${1:source} === '${2:undefined}'
${1:source} instanceof ${2:Object}
BDD-style testing shortcuts for Intern, Mocha, Jasmine and others
describe('${1:description}', function () {
$0
})
it('${1:description}', function() {
$0
})
expect($1).$0
Timer shortcuts
setTimeout(function () {
$0
}, ${1:delay});
setTimeout(function () {
$0
}, ${1:delay});
The following snippets apply only within Node.js or scripts with Browserify
function (err${1:, value}) {$0}
${1:var ${2:variable}} = require('${3:module}')
exports.${1:name} = ${2:value};
module.exports = ${1:name};
${1:${2:emitter}.}on('${3:event}', function(${4:arguments}) {
$0
})