Merge pull request #15 from ekalinin/patch-1

Added new snippets for JavaScript
This commit is contained in:
Honza Pokorny 2011-08-03 02:57:07 -07:00
commit 86816b8b3e

View File

@ -94,3 +94,64 @@ snippet gett
# console.log (Firebug) # console.log (Firebug)
snippet cl snippet cl
console.log(${1}); console.log(${1});
# return
snippet ret
return ${1:result}
# for (property in object ) { ... }
snippet fori
for (var ${1:prop} in ${2:Things}) {
${3:$2[$1]}
};
# hasOwnProperty
snippet has
hasOwnProperty(${1})
# docstring
snippet /**
/**
* ${1:description}
*
*/
snippet @par
@param {${1:type}} ${2:name} ${3:description}
snippet @ret
@return {${1:type}} ${2:description}
# JSON.parse
snippet jsonp
JSON.parse(${1:jstr});
# JSON.stringify
snippet jsons
JSON.stringify(${1:object});
# self-defining function
snippet sdf
var ${1:function_name} = function (${2:argument}) {
${3:// initial code ...}
$1 = function ($2) {
${4:// main code}
};
}
# singleton
snippet sing
function ${1:Singleton} (${2:argument}) {
// the cached instance
var instance;
// rewrite the constructor
$1 = function $1($2) {
return instance;
};
// carry over the prototype properties
$1.prototype = this;
// the instance
instance = new $1();
// reset the constructor pointer
instance.constructor = $1;
${3:// code ...}
return instance;
}