0
我搞亂了一個JavaScript模式,將允許我命名空間我的代碼,並定義內部全球範圍內的快捷方式,以減少打字量我將不得不做。javascript設計模式不返回intellisense的一些對象
像$而不是jQuery或$ messageType而不是messages.messageType。
雖然模式似乎是在Visual Studio 2010
例如現在的工作很好我已經失去了一定的智能感知功能我下面的測試函數會提醒「成功」,但我的智能感知不會通過$ messageType對象屬性枚舉。
由於生產力是關鍵,這對我來說是個大問題。
有什麼我錯過了JavaScript的大師可以拿起?
這是一個jsfiddle玩。
; (function (window) {
// Define a local copy of myObject
var myObject = function() {
// The myObject object is actually just the init constructor 'enhanced'
return new myObject.fn.init();
},
// Shortcuts.
// A central reference to the root messages object
$messages = null,
// A central reference to the root messages.messageType object
$messageType = null;
myObject.fn = myObject.prototype = {
init: function() {
// Initialise the object shortcuts.
$messages = this.messages;
$messageType = this.messages.messageType;
}
};
// Give the init function the myObject prototype for later instantiation
myObject.fn.init.prototype = myObject.fn;
myObject.fn.messages = {
/// <summary>
/// Provides means to provide feedback message to the client.
/// </summary>
messageType: {
information: "information",
error: "error",
success: "success"
}
};
myObject.fn.tester = function() {
alert($messageType.success);
};
// Expose myObject to the global object
window.myObject = window.$m = myObject();
} (window));
jQuery(document).ready(function() {
$m.tester();
});