2
假設我們正在構建一個嵌套命名空間,我們將根據需要對多個對象進行原型設計。默認情況下,對象window.blah.foo是空的。然後,我們將所有子對象和它們的功能原型化爲一個原型。當我們在下面進行記錄時,我們將所有內部函數顯示爲全局變量。現在想象你有幾十個以相同方式構建的文件。我們如何記錄這一點,以便.bar1(),bar2()和bar3()函數是window.blah.foo對象的方法,特別是當它的實例化發生在該文件之外時,可能多次。記錄原型繼承的JSDoc
/**
* Blah - Our very own global Namespace
* @namespace
* @type {object}
* @global
* @public
*/
window.blah = window.blah || {};
/**
* Immediately-Invoked Function Expression (IIFE).
* @function
* @param {object} w - Global window object.
* @returns {Object} window.blah.foo
*/
(function (w) {
// strict JS
'use strict';
/**
* Create instance of w.blah.foo constructor
* @constructor
*/
w.blah.foo = function() {
};
/**
* Append properties and methods to an instance of window.blah.foo
* @constructor
*/
w.blah.foo.prototype = {
/**
* Dummy function to return the number 1.
* @method bar1
*/
bar1: function() {
console.log(1);
},
/**
* Dummy function to return the number 2.
* @method bar2
*/
bar2: function() {
console.log(2);
},
/**
* Dummy function to return the number 3.
* @method bar3
*/
bar3: function() {
console.log(3);
}
};
}(window));
謝謝!我知道某處已經錯過了一個標籤。 –