Last active
December 17, 2015 03:49
-
-
Save Skateside/5546361 to your computer and use it in GitHub Desktop.
This is a simple exploration of the Google Closure Compiler's use of JSDoc and the @type's needed to validate the code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
General notes: | |
Curly braces around the types seem to be optional. "{number}" works the same as | |
"number". | |
*/ | |
/** | |
* @type {boolean} bool | |
*/ | |
var bool = true; | |
/** | |
* @type {number} num | |
*/ | |
var num = 1; | |
/** | |
* @type {string} str | |
*/ | |
var str = ''; | |
/** | |
* "null", "Null" and "Object" seem to work here. | |
* | |
* @type {null} nul | |
*/ | |
var nul = null; | |
/** | |
* @type {undefined} undef | |
*/ | |
var undef = undefined; | |
/** | |
* @type {Array} arr | |
*/ | |
var arr = []; | |
/** | |
* @type {Object} obj | |
*/ | |
var obj = {}; | |
/** | |
* @type {RegExp} reg | |
*/ | |
var reg = /a/; | |
/** | |
* @type {Function} fn | |
*/ | |
var fn = function () {}; | |
/** | |
* @type {Date} date | |
*/ | |
var date = new Date(); | |
/** | |
* The constructor tag is needed or the "Foo" type will not be recognised. | |
* | |
* @constructor | |
*/ | |
function Foo() { | |
} | |
/** | |
* @type {Foo} foo | |
*/ | |
var foo = new Foo(); | |
/** | |
* @type {Element} dom | |
*/ | |
var dom = document.createElement('p'); | |
/** | |
* The asterisk denotes any type or "mixed" | |
* | |
* @type {*} mixed | |
*/ | |
var mixed = ['a', 1, {}, []][Math.floor(Math.random() * 4)]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment