开发者

How to design a Library?

开发者 https://www.devze.com 2022-12-14 18:12 出处:网络
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 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 -

  1. Identify what functions you write often.
  2. Save them in a seperate .js file.
  3. Keep a log or comment block on top of the development version and update to reflect the contents of the file.

Done.


  1. Use a webservice for connect to db and exec the queries..

  2. Create SERVICE.JS, in this file call web service with jquery.ajax method

  3. Create a DESIGN.JS, in this file do everythig about user ınterface (onclick, initialize,fill grids,combos etc)

  4. Create a GLOBAL.JS, in this file create global variables for use everywhere(for example: UserId)

  5. Create a HELPER.JS, in this file create useful functions for use anywhere(for example: function DATE_TO_STRING(_date) )

  6. On this all .JS files use namespaces example for GLOBAL.JS:

    (function () {
    var GLOBAL = {
    
      CurrentUserId:-1
    }
    
    if (!window.GLOBAL) { window.GLOBAL = GLOBAL; }
    

    })();

  7. Dont use ASP.NET components. Use html inputs,textarea etc

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号