Я использую следующий шаблон всякий раз, когда пишу большую библиотеку JavaScript для веб-сайтов.
Хотя все выглядит нормально во время выполнения, в visual studio всегда есть кошмар.
В последней строкеиз выражения анонимной функции я всегда получаю ошибку
«Ожидается;»
в последней закрывающей скобке
} (окно,jQuery));
Я без проблем запустил код через jslint, но мой intellisense всегда ломается, и я не могу отформатировать код.я что-то пропустил?
; (function (window, $) {
// Define a local copy of MyLibrary
var MyLibrary = {},
// Shortcuts.
// A central reference to the root messages object
$$messages,
// A central reference to the root messages.messageType object
$$messageType;
MyLibrary = function () {
// The MyLibrary object is actually just the init
// constructor 'enhanced'
return new MyLibrary.fn.init();
};
MyLibrary.fn = MyLibrary.prototype = {
init: function () {
// Initialise the object shortcuts.
$$messages = MyLibrary.fn.messages;
$$messageType = MyLibrary.fn.messages.messageType;
}
};
// Give the init function the MyLibrary prototype for later instantiation
MyLibrary.fn.init.prototype = MyLibrary.fn;
MyLibrary.fn.messages = {
/// <summary>
/// Provides means to provide feedback message to the client.
/// </summary>
messageType: {
information: "information",
error: "error",
success: "success"
}
};
MyLibrary.fn.tester = function () {
alert($$messageType.success);
};
// Expose MyLibrary to the global object
window.MyLibrary = window.$m = MyLibrary();
} (window, jQuery));
jQuery(document).ready(function () {
$m.tester();
});