Atlas slash!!!轮回1

直入正题吧!!!
Atlas剖析:
Atlas使用了一系列ASP.NET Server Controls, Web Services 和 JavaScript libraries.

使JavaScript更简单:
Atlas对JavaScript附加了很多类型系统扩展,如namespace, 继承, 接口, 枚举 和 添加了如 String 和 Array等等助手类型(helper).简而言之,Atlas是一种扩展的JavaScript语言.

下面来看看Atlas的一些主要扩展:
Namespace
Inheritance
Interface

使用Namespace
e.g.:

Type.registerNamespace("Demo");

Demo.Person = function(firstName, lastName, alias)
{
    var _firstName = firstName;
    var _lastName = lastName;
   
    this.getFirstName = function() {
        return _firstName;
    }
   
    ...
}
Type.registerClass('Demo.Person', null, Web.IDisposable);

Inheritance
e.g:

Type.registerNamespace("Demo");

Demo.Person = function(firstName, lastName, emailAddress) {
    var _firstName = firstName;
    var _lastName = lastName;
    var _emailAddress = emailAddress;
   
    this.getFirstName = function() {
        return _firstName;
    }
   
    ...
   
    this.dispose = function() {
        alert('bye ' + this.getName());
    }
}
Type.registerClass('Demo.Person', null, Web.IDisposable);

...

Demo.Person.prototype.toString = function() {
    return this.getName() + ' (' + this.getEmailAddress() + ')';
}

Demo.Employee = function(firstName, lastName, emailAddress, team, title) {
    Demo.Employee.initializeBase(this, [firstName, lastName, emailAddress]);
   
    var _team = team;
    var _title = title;
   
    this.getTeam = function() {
        return _team;
    }
    this.setTeam = function(team) {
        _team = team;
    }
   
    ...
}
Type.registerClass('Demo.Employee', Demo.Person);

Demo.Employee.prototype.toString = function() {
    return Demo.Employee.callBaseMethod(this, 'toString') + '/r/n' + this.getTitle() + '/r/n' + this.getTeam();

Interface

e.g.:

Type.registerNamespace("Demo.Animals");

Demo.Animals.IPet = function() {
    this.getFriendlyName = Function.abstractMethod;
}
Type.registerInterface('Demo.Animals.IPet');


Demo.Animals.Animal = function(name) {
    var _name = name;
   
    this.getName = function() {
        return _name;
    }
}
Type.registerAbstractClass('Demo.Animals.Animal');

Demo.Animals.Animal.prototype.toStringCustom = function() {
    return this.getName();
}
Demo.Animals.Animal.prototype.speak = Function.abstractMethod;


Demo.Animals.Pet = function(name, friendlyName) {
    Demo.Animals.Pet.initializeBase(this, [name]);
   
    var _friendlyName = friendlyName;
    this.getFriendlyName = function() {
        return _friendlyName;
    }
}
Type.registerAbstractClass('Demo.Animals.Pet', Demo.Animals.Animal, Demo.Animals.IPet);


Demo.Animals.Cat = function(friendlyName) {
    Demo.Animals.Cat.initializeBase(this, ['Cat', friendlyName]);
}
Type.registerClass('Demo.Animals.Cat', Demo.Animals.Pet);

Demo.Animals.Cat.prototype.speak = function() {
    alert('meow');
}

Demo.Animals.Cat.prototype.toStringCustom = function() {
    return 'Pet ' + Demo.Animals.Cat.callBaseMethod(this, 'toStringCustom');
}

Demo.Animals.Felix = function() {
    Demo.Animals.Felix.initializeBase(this, ['Felix']);
}
Type.registerClass('Demo.Animals.Felix', Demo.Animals.Cat);

Demo.Animals.Felix.prototype.toStringCustom = function() {
    return Demo.Animals.Felix.callBaseMethod(this, 'toStringCustom') + ' ... its Felix!';
}


Demo.Animals.Dog = function(friendlyName) {
    Demo.Animals.Dog.initializeBase(this, ['Dog', friendlyName]);
}
Type.registerClass('Demo.Animals.Dog', Demo.Animals.Pet);

Demo.Animals.Dog.prototype.speak = function() {
    alert('woof');
}


Demo.Animals.Tiger = function() {
    Demo.Animals.Tiger.initializeBase(this, ['Tiger']);
}
Type.registerClass('Demo.Animals.Tiger', Demo.Animals.Animal);

Demo.Animals.Tiger.prototype.speak = function() {
    alert('grrr');
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值