javascriptдÀ෽ʽ֮ʮ
10¡¢mootools.jsµÄдÀ෽ʽ
mootools.jsµÄ×îа汾ÊÇ1.2.3,ÕâÀïʹÓõÄÊÇ1.2.0¡£mootool±»Éè¼Æ³É·Ç³£½ô´ÕµÄ£¬Ä£¿é»¯µÄ£¬ÃæÏò¶ÔÏóµÄµÄjs¿â¡£mootoolÖÐдÀàÓÃClassÀà¡£ClassÀàÓÉNativeÀànew³öÀ´µÄ£º
/*
*Script: Class.js
*/
var Class = new Native({
name: 'Class',
initialize: function(properties){
properties = properties || {};
var klass = function(empty){
for (var key in this) this[key] = $unlink(this[key]);
for (var mutator in Class.Mutators){
if (!this[mutator]) continue;
Class.Mutators[mutator](this, this[mutator]);
delete this[mutator];
}
this.constructor = klass;
if (empty === $empty) return this;
var self = (this.initialize) ? this.initialize.apply(this, arguments) : this;
if (this.options && this.options.initialize) this.options.initialize.call(this);
return self;
};
$extend(klass, this);
klass.constructor = Class;
klass.prototype = properties;
return klass;
}
});
Native·½·¨ÊÇmootoolsÖÐÒ»¸ö·Ç³£ÖØÒªµÄ·½·¨£¬ºÜ¶àÀà¶¼ÓÃËüÈ¥×é×°¡£ÈçWindow,Document,Event¡£µ±È»»¹ÓÐÕâÀïµÄClass£¬µ¼ÈëmootoolsºóÎÒÃÇдÀàʱֻÐèÒªÓÃClass¾ÍÐÐÁË¡£Ò»¸öPersonÀࣺ
/**
* PersonÀà
* @param {Object} name
*/
var Person = new Class({
initialize: function(name){
this.name = name;
},
setName : function(name) {
this.name = name;
},
getName : function() {
return this.name;
}
})
//newÒ»¸ö¶ÔÏó
var p = new Person("jack");
//²âÊÔset£¬get·½·¨
console.log(p.getName());//jac
p.setName('andy');
console.log(p.getName());//andy
//²âÊÔinstanceof¼°p.constructorÊÇ·ñÕýÈ·Ö¸ÏòÁËPerson
console.log(p instanceof Person); //true
console.log(p.constructor == Person); //true
Nativeʵ¼ÊÉÏÖ»ÊÇÒ»¸öÆÕͨº¯Êý£¬Ëüͨ¹ýËù´«²ÎÊý×é×°ÁËÒ»¸öÀࣨfunction£©£¬×îºó·µ»Ø¸ÃÀࣨfunction£©¡£¼ÈÈ»NativeÊǺ¯Êý£¬º¯
Êýµ÷Óõķ½Ê½ÊÇ(),call,apply¡£µ«ÔÚmootoolsÖÐÈ´ÓÃnew
Native(obj)·½Ê½¡£ÎªºÎ£¿ÔÒòÖ»ÊÇʹNative¿´ÆðÀ´¸üÏñÒ»¸öÀà¶øÒÑ¡£¼û¾ßÃûº¯ÊýµÄËÄÖÖµ÷Ó÷½Ê½£¨3£©
Ïà¹ØÎĵµ£º
Build your web applications quickly and easily using the industry leading web application IDE -- Aptana Studio.
Introduction:
Aptana Studio is a complete web development environment that combines powerful authoring tools for HTML, CSS, and JavaScript, along with thousands of additional plugins ......
<html>19Â¥¿Õ¼ä,`(uqj3~9?!F
<body>
Ob*p#?L;DL0<scrīpt LANGUAGE="Javascrīpt">
+t:{z]tbs0var s = "";19Â¥¿Õ¼äe kA3HoT1H
s += "ÍøÒ³¿É¼ûÇøÓò¿í£º" + document.body.clientWidth;19Â¥¿Õ¼äcy2if}:H/SE@
s += "<br>ÍøÒ³¿É¼ûÇøÓò¸ß£º"+ document.bo ......
5¡¢Óà ¹¹Ô캯Êý+ÔÐÍ ¶¨ÒåÒ»¸öÀࣻͬһ¹¹Ô캯Êý¿ÉÒÔ¶¨Òå³ö¶à¸öÀàÐÍ
/**
* $define дÀ๤¾ßº¯ÊýÖ®¶þ
* @param {Object} constructor
* @param {Object} prototype
*/
function $define(constructor,prototype) {
var c = constructor || function(){};
var p = prototype || {};
r ......
ÕâÆª¿ªÊ¼»á·ÖÎöÁ÷ÐеÄjs¿â֮дÀ෽ʽ¡£¸÷ÖÖ¿âµÄдÀ෽ʽËäÈ»Ç§Ææ°Ù¹Ö£¬µ«ÈÔÈ»ÌÓÀë²»Á˱¾ÖÊ---Óù¹Ô캯ÊýºÍÔÐÍ
À´×é×°Àà¡£
6¡¢Prototype.jsµÄдÀ෽ʽ
//prototype.jsÖеĴúÂë
var Class = {
create: function() {
return function() {
this.initialize.apply(this, arguments);
}
}
}
//¼ò»¯ ......
8¡¢Ext.jsµÄдÀ෽ʽ
ÕâÀïÓõÄÊÇExt core3.0£¬ExtÖÐÓÃExt.extendÀ´¶¨ÒåÒ»¸öÀࣨµ±È»Ëü¸ü¶àÓÃÀ´À©Õ¹Ò»¸öÀࣩ£¬ExtÕû¸ö¿ò¼Ü¸÷ÖֿؼþÈçPanel£¬MessageBoxµÈ¶¼ÊÇÓÃExt.extend·½·¨À´À©Õ¹¡£ÕâÀï½ö½öÓÃËüÀ´¶¨ÒåÒ»¸ö×î¼òµ¥µÄÀà¡£
¿´Ext.extendµÄ´úÂë¿ÉµÃÖª£¬ËüÈÔÈ»ÊÇÓù¹Ô캯ÊýºÍÔÐÍÀ´×é×°Ò»¸öÀà¡£
ÕâÀïÖ»Ðè´«Á½¸ö²ÎÊý¼´¿É£¬µÚÒ ......