易截截图软件、单文件、免安装、纯绿色、仅160KB

javascript框架之继承机制2

 我们来模仿一下最OO的mootools的继承机制。它的类都有一个叫做initialize构造方法,这与Java的类都有一个与类名同名的构造方法一样的道理。只不过,这些叫initialize或init都是借鉴自Prototype,而Prototype那帮人是Ruby出身。为了区别mootools那种污染原生方法的做法,我把类的构造器命名为variant,并且禁止查看构造方法(像浏览器禁止查看原生对象的构造方法那样)。
 
    var variant = function (options){
      options = options || {};
      var initialize = options.initialize || function(){};
      var klass = initialize ;
      klass.constructor = arguments.callee;
      klass.prototype.constructor = klass;
      klass.toString = function(){//禁止查看构造方法
        return "function variant(){\n    [variant code]\n}"
      }
      return klass;
    };
    var Person = variant({initialize:function(age){
        this.age = age;
      }});
    alert(Person)//看不到构造方法的实现
    var p = new Person(3);
    alert(p)
    alert(p.age);
    alert(p.constructor);//看不到构造方法的实现
    var P = variant({})
    var a = new P;
    alert(a);
 
运行代码
    var variant = function (options){
      options = options || {};
      var initialize = options.initialize || function(){};
      var klass = initialize ;
      klass.constructor = arguments.callee;
      klass.prototype.constructor = klass;
      klass.toString = fu


相关文档:

用javascript操纵GridView中CheckBox的两个常用技巧

  using System;
using System.Data;
public partial class CheckBox:System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//生成DataTable并添加相应的列
DataTable dt = new DataTable();
dt.Columns.Add("ID");
dt.Columns.Add("Autho ......

深入解JavaScript函数

JavaScript函数语法
函数是进行模块化程序设计的基础,编写复杂的Ajax应用程序,必须对函数有更深入的了解。javascript中的函数不同于其他的语言,每个函 数都是作为一个对象被维护和运行的。通过函数对象的性质,可以很方便的将一个函数赋值给一个变量或者将函数作为参数传递。在继续讲述之前,先看一下函数的 使用语法: ......

[从jQuery看JavaScript]

jQuery片段:
var
// Will speed up references to window, and allows munging its name.
window = this,
// Will speed up references to undefined, and allows munging its name.
undefined,
// Map over jQuery in case of overwrite
_jQuery = window.jQuery,
// Map over the $ in case of overwrit ......

Javascript操作下拉框的常用方法

 function AddDropDownList(id,fatherCtl)
{
    if(!document.getElementById(id))
    {
        var ddl = document.createElement('select');
        ddl.s ......

操作ClassName的工具函数(JavaScript权威指南)

/**
* CSSClass.js
*/
var CSSClass = {}; //Create our namespace object
//Return tru if element e is a member of the class c;false otherwise
CSSClass.is = fucntion(e, c)
{
if(typeof e == "string")
e = document.getElementById(e);
//Before doing a regexp search,optimize for couple of co ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号