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();
});