How to design a Library?
We have just started our new assignment - web-based project. Before I get directly on to the question it would be necessary to explain about the project.
We are actually moving a product from desktop to web. This is it. All backend services are web services. Our choice of server technology will be .NET. As we are good with it and also client are equipped with it too. So, we will be doing all the server work in ASP.NET AJAX. PageMethod will be preferred choice to communicate with server (C# 3.0) and client (JavaScipt). There will be a real need of jQuery for parsing DOM and XML parsing. We do not to put effort to reinvent the wheel.
Now, there are things what we have开发者_高级运维 to do and mostly it will be in JavaScript. We would like to package it in one.
E. John did a very useful session on 'Building a JavaScript Library' which is very useful. It surely keep in this way.
A fairly good amount of JavaScript engineers are here. And I would like to have their recommendations and suggestions before we start over.
Do you know some good references on JavaScript Library design? If you every made your own JS Library what you learned from it? Have you look into gmail/googledocs/facebook JavaScript? What have you learned from it?
Thanks.
Start off with something like this:
var yourNamespace = yourNamespace || (function () {
"use strict";
// private variables here
return {{whatever you want yourNamespace to be here}};
}());
To design a javascript library -
- Identify what functions you write often.
- Save them in a seperate .js file.
- Keep a log or comment block on top of the development version and update to reflect the contents of the file.
Done.
Use a webservice for connect to db and exec the queries..
Create SERVICE.JS, in this file call web service with jquery.ajax method
Create a DESIGN.JS, in this file do everythig about user ınterface (onclick, initialize,fill grids,combos etc)
Create a GLOBAL.JS, in this file create global variables for use everywhere(for example: UserId)
Create a HELPER.JS, in this file create useful functions for use anywhere(for example: function DATE_TO_STRING(_date) )
On this all .JS files use namespaces example for GLOBAL.JS:
(function () { var GLOBAL = { CurrentUserId:-1 } if (!window.GLOBAL) { window.GLOBAL = GLOBAL; }
})();
Dont use ASP.NET components. Use html inputs,textarea etc
精彩评论