Last active
July 8, 2024 15:48
-
-
Save dotherightthing/b552b1d5b81a1a4808019cbdfc9cf31a to your computer and use it in GitHub Desktop.
[Revealing module pattern] #js #jsdoc #es5 #trycatch #throw
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
// some-component.js | |
// see https://www.youtube.com/watch?v=pOfwp6VlnlM. | |
/** | |
* @file Do something | |
* @author [email protected] | |
* @requires jquery.js | |
*/ | |
/** | |
* jQuery object | |
* | |
* @external jQuery | |
* @see {@link http://api.jquery.com/jQuery/} | |
*/ | |
/** | |
* @namespace SomeComponent | |
*/ | |
var SomeComponent = (function () { | |
'use strict'; | |
/** | |
* @property {object} _options - Module options | |
* @memberof SomeComponent | |
* @protected | |
* | |
* @property {external:jQuery} _options.$test - The test container | |
*/ | |
var _options = { | |
$test: $('#test'), | |
}; | |
/** | |
* @function getOptProp | |
* @summary Get an option property. | |
* @memberof SomeComponent | |
* @public | |
* | |
* @param {string} optionProperty - An option property | |
* @returns {string} - Option value | |
*/ | |
var getOptProp = function (optionProperty) { | |
try { | |
if (_options.hasOwnProperty(optionProperty)) { | |
return _options[optionProperty]; | |
} | |
throw new Error('Object does not have property ' + optionProperty); | |
} catch (e) { | |
console.error(e); | |
} | |
}; | |
return { | |
getOptProp: getOptProp, | |
}; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment