module-pattern

What is the intention of Ninject modules?

不羁的心 提交于 2019-12-17 15:35:29
问题 I'm a complete newbie to ninject I've been pulling apart someone else's code and found several instances of nInject modules - classes that derive from Ninject.Modules.Module, and have a load method that contains most of their code. These classes are called by invoking the LoadModule method of an instance of StandardKernel and passing it an instance of the module class. Maybe I'm missing something obvious here, but what is the benefit of this over just creating a plain old class and calling

Javascript: Module Pattern vs Constructor/Prototype pattern?

拜拜、爱过 提交于 2019-12-17 15:06:59
问题 I would like to know if the module pattern or Constructor/protoType pattern is more applicable to my work. Basically I am using unobtrusive javascript -- the HTML document has a reference to the .js file. My understanding of the module pattern: call an INIT method (which is basically a public method i can create and return using the module pattern) In the INIT method, assign all click events etc. This sounds like the perfect pattern for my situation, as I don't need to create Objects and

In Javascript/Coffeescript how can I mock out a module's public variable in a test?

℡╲_俬逩灬. 提交于 2019-12-13 05:44:39
问题 I just learned about the module pattern. I've written some code that's gotten sufficiently complex that I want to test a feature. The problem is, I can't figure out how to mock out a value. What follows is coffeescript, but I'll put the generated javascript below so I can get more help. Here's my test that attempts to mock out a field named state , but it always prints "undefined": root = exports ? this root.test3 = (-> root.test2.state = "abc" root.test2.doSomething() return {} )() And here

Javascript module pattern introduced in TGP deentityify method - why is this pattern necessary?

不羁岁月 提交于 2019-12-12 21:37:45
问题 Crockford introduces a pattern in the deentityify method to create a module. He claims: The module pattern takes advantage of function scope and close to create relationships that are binding and private. In this example, only the deentityify method has access to the entity data structure. Distilling to remove his custom functions, I think the code boils down to... String.prototype.deentityify = function() { var entity = { quot: '"', lt: '<', gt: '>' }; return function() { return this.replace

Square bracket notation and scope in JavaScript module pattern

痴心易碎 提交于 2019-12-10 14:53:47
问题 I have been working with the module pattern in JavaScript and have a question about scope and square bracket notation (SBN). Please consider the following simple example. (function (module) { function myMethod(text) { console.log(text); } module.init = function (name) { // here I want to do something like // eval(name)("hello"); // using SBN, e.g. ..[name].call(this, "hello"); }; })(window.Module = window.Module || {}); Module.init("myMethod"); From within the init function is it possible to

Javascript Module pattern, Prototype and Google Closure

谁说胖子不能爱 提交于 2019-12-10 10:59:50
问题 I am having trouble getting this code structure to survive obfuscation with the Google Closure Compiler. Here's some sample code: var MyModule = (function() { function myModule() { // Constructor } function moduleFoo(url) { // Method } function moduleBar() { // Method } myModule.prototype = { constructor: myModule, foo: moduleFoo, bar: moduleBar }; return myModule; })(); Elsewhere in my code I need be able to write things like the following: var myMod = new MyModule(); myMod.foo(); myMod.bar(

Javascript Module pattern, Prototype and Google Closure

两盒软妹~` 提交于 2019-12-06 14:07:23
I am having trouble getting this code structure to survive obfuscation with the Google Closure Compiler. Here's some sample code: var MyModule = (function() { function myModule() { // Constructor } function moduleFoo(url) { // Method } function moduleBar() { // Method } myModule.prototype = { constructor: myModule, foo: moduleFoo, bar: moduleBar }; return myModule; })(); Elsewhere in my code I need be able to write things like the following: var myMod = new MyModule(); myMod.foo(); myMod.bar(); However the compiler is renaming everything (as expected). How can I make the prototype that I have

Using the Module Pattern for larger projects

谁都会走 提交于 2019-12-05 10:31:49
问题 I'm interested in using the Module Pattern to better organize my future projects. Unfortunately, there are only a few brief tutorials and proof-of-concept examples of the Module Pattern. Using the module pattern, I would like to organize projects into this sort of structure: project.arm.object.method(); Where "project" is my global project name, "arm" is a sub-section or branch of the project, "object" is an individual object, and so on to the methods and properties. However, I'm not sure how

How can I transition my Module-Singleton JavaScript to supporting instances?

旧巷老猫 提交于 2019-12-04 14:09:20
问题 I've been writing an application and I have had a lot of success breaking different pieces of functionality into the so called "Module" pattern where you have a self-executing singleton with public and private members. var WidgetModule = (function($, options) { // Private variable var someVar; // Private functions function somePrivateFunction() { } // Define the public members var self = { init: function() { }, someFunction: function() { } }; return self; })(jQuery, options); I have now run

JavaScript - extract out function while keeping it private

时光毁灭记忆、已成空白 提交于 2019-12-04 07:09:40
问题 Currently I have this structure: (function(myScope) { myScope.public = function() {alert("I'm public!")}; myScope.privileged = function() {alert("I can call private!"); private();}; var private = function() {alert("I'm private!")}; })(window.myObj); It works fine. private is not accessible from the outside world while privileged can call it. But now the private parts are too big such that I hope to extract it out. I want to keep it inaccessible from the outside but it needs to be invoked by