zoukankan      html  css  js  c++  java
  • js在mootools框架下的new Class

          首先,在HTML文件中引入mootools.js、 mootools-more.js、mootools-core.js,然后就能使用mootools封装的一些特性。

    几乎类似于面向对象。

          mootools使用如下形式构建对象:

    1 var Cat = new Class(
    2 {
    3      initialize: function(name) //类似于Java的构造函数
    4      {
    5           this.name = name;
    6      }
    7 });

           用如下形式进行继承:

    var littleCat = Cat.extend(
      {
           initialize:function(name,age)
           {
                  this.parent(name); //调用父类的initialize方法
                  this.age = age;
           }
      });

           对象的实例化及使用:

    var mycat = new Cat('kity'); //注意还有一个new存在
    alert(mycat.name);
        
    var littlecat = new littleCat('litterkity','ten');
    alert(littlecat.name + ' is ' + littlecat.age + ' days old');

    var Cat = new Class(
      {
           initialize: function(name)
           {
                 this.name = name;
           }
      });
     
      var littleCat = Cat.extend(
      {
           initialize:function(name,age)
           {
                  this.parent(name);
                  this.age = age;
           }
      });
     
        var mycat = new Cat('kity');
        alert(mycat.name);
        
        var littlecat = new littleCat('litterkity','ten');
        alert(littlecat.name + ' is ' + littlecat.age + ' days old');

  • 相关阅读:
    Leetcode 349. Intersection of Two Arrays
    hdu 1016 Prime Ring Problem
    map 树木品种
    油田合并
    函数学习
    Leetcode 103. Binary Tree Zigzag Level Order Traversal
    Leetcode 102. Binary Tree Level Order Traversal
    Leetcode 101. Symmetric Tree
    poj 2524 Ubiquitous Religions(宗教信仰)
    pat 1009. 说反话 (20)
  • 原文地址:https://www.cnblogs.com/benbenduo/p/3731677.html
Copyright © 2011-2022 走看看