...
- A control should have one javascript file and one HTML template file with the same name.
example: html/BillingShippingAddress.html and js/BillingShippingAddress.js - HTML template file should have plain HTML tags with knockout attributes
example:<div class="form-group">
<label class="caption">Username</label>
<input class="form-control" type="email" placeholder="Username / Email" required autofocus="" data-bind="value: userName>
</div> - A control's name should unique and meaningful and should not duplicate.
example: BillingShippingAddress.html and BillingShippingAddress.js - A javascript variable will be created that will act as a collection for all of the controls objects.
example : var eb_billingShippingAddress = eb_billingShippingAddress || {}; - Control's properties, functions and methods name should start with came case.
example: productCatalogPage - Any object at the collection level should be generic to all instances of that control. Instance-specific information should live at the model level. SitePath, TemplatePath and ServicePath would be fixed properties for each control. These variables should be prefixed with an eb_prefix so that it does not collide with other JavaScript systems.
example :
eb_billingShippingAddress.SitePath = eb_Config.SitePath;
eb_billingShippingAddress.TemplatePath = "html/BillingShippingAddress.html";
eb_billingShippingAddress.ServicePath = eb_Config.ServicePath; - The Path of the HTML template should mirror that of the path to the JS.
example: eb_billingShippingAddress.TemplatePath = "html/BillingShippingAddress.html"; - Each model's properties / field should be defined camel case and assign to ko.observable / ko.observableArray / ko.computed based on logic.
example:
var _that = this;
_that.domElement = options.domElement;_that.showError = ko.observable(0);
_that.errorMessage = ko.observable();
_that.showSuccess = ko.observable(0);
_that.successMessage = ko.observable();
_that.billingAddress = ko.observableArray(); - Should not use 'this' object directly in function. It should use Create local variable var _self = this; and use it.
Each model's function's name should be meaningful and scope should be model's context.
example:_that.toggleShipping = function () {
_that.shippingAddressCollapse(!_that.shippingAddressCollapse());
};
...