Skip to content

Add example for Revealing Module Pattern. #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions Jake/articles/howto-commonjs-modules
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,53 @@ define('my/shirt', function () {
});
{{/example}}

<h3>Document an IIFE which exposes local functions (Revealing Module Pattern)</h3>

<p>The <a href="http://addyosmani.com/resources/essentialjsdesignpatterns/book/#revealingmodulepatternjavascript">Revealing Module Pattern</a> requires that you mark each method as a memberOf the module.</p>

{{#example}}The getColor method is documented as a member of the "shirt" module.
/** A module representing a shirt.
* @module shirt
*/
var shirt = (function() {

var color = 'black';

/** Gets the color of the shirt.
* @memberOf module:shirt#
*/
function getColor() {
return color;
}

return {
getColor: getColor
}

})();
define('shirt', function () {
/**
* A module representing a shirt.
* @exports my/shirt
* @version 1.0
*/
var shirt = {

/** A property of the module. */
color: "black",

/** @constructor */
Turtleneck: function(size) {
/** A property of the class. */
this.size = size;
}
};

return shirt;
});
{{/example}}



<h3>Document a Module as a Constructor</h3>

Expand Down