Skip to content

Instantly share code, notes, and snippets.

@dotherightthing
Last active July 8, 2024 15:48
Show Gist options
  • Save dotherightthing/b552b1d5b81a1a4808019cbdfc9cf31a to your computer and use it in GitHub Desktop.
Save dotherightthing/b552b1d5b81a1a4808019cbdfc9cf31a to your computer and use it in GitHub Desktop.
[Revealing module pattern] #js #jsdoc #es5 #trycatch #throw
// some-component.js
// see https://www.youtube.com/watch?v=pOfwp6VlnlM.
/**
* @file Do something
* @author your.name@domain.com
* @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