2007年03月08日 星期四 22:49
Brightman дµÀ:
> ajax_form.js´úÂëÈçÏ£ºÎÒ²»´ó¶®ÄÇЩÊÇÀàÄÇЩÊÇÀà³ÉÔ±º¯Êý
>
> __data_handle = function(target, data){ //ÕâÊǶ¨ÒåÒ»¸öÀàô£¿»¹ÊǺ¯Êý
> var obj = target;
> var e = obj.form;
> //remove all error infos
> $('.error', e).remove();
> ............
> }
>
> AjaxForm = function(form, options){ //ÕâÊǶ¨ÒåÒ»¸öÀàô£¿»¹ÊǺ¯Êý
> this.options = options || {};
> this.form = $(form);
> this.hookajax();
> }
>
> Object.extend(AjaxForm.prototype, { //exten ¼Ì³Ð¸¸Ààô£¿
> setdata: function(objs){ //³ÉÔ±º¯Êý£¿
> $H(objs).each(function(k, v){
> $("[@name='$0']".template([k]), this.e).val(v);
> });
> return this;
> },
>
> hookajax: function(){
> .....................
> }
>
> });
>
>
> ÔÚÍøÉÏûÕÒµ½ºÏÊʵÄjavascript classµÄ½Ì³Ì,²»´ó¶®¹ÊÀ´Çë½Ì¡£Ð»Ð»£¡
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070308/476aed1f/attachment.htm
2007年03月08日 星期四 23:07
javascript 没有正式的"类"的说法,但是可以利用 function 来模拟类的一些简单行为。
a = function(){
alert('b');
}
这种方式只是定义一个匿名函数,然后把它赋值给 a 这个变量。
js 中模拟类编程的一个重要方法是用 prototype 的方式扩展。
在 07-3-8,Brightman<mr.brightman在gmail.com> 写道:
>
> Brightman 写道:
> ajax_form.js代码如下:我不大懂那些是类那些是类成员函数
>
> __data_handle = function(target, data){ //这是定 义一个类么?还是函数
> var obj = target;
> var e = obj.form;
> //remove all error infos
> $('.error', e).remove();
> ............
> }
>
> AjaxForm = function(form, options){ //这是定义一 个类么?还是函数
> this.options = options || {};
> this.form = $(form);
> this.hookajax();
> }
>
> Object.extend(AjaxForm.prototype, { //exten 继承父类么?
> setdata: function(objs){ //成员 函数?
> $H(objs).each(function(k, v){
> $("[@name='$0']".template([k]), this.e).val(v);
> });
> return this;
> },
>
> hookajax: function(){
> .....................
> }
>
> });
>
>
> 在网上没找到合适的javascript class的教程,不大懂故来请教。谢谢!
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to
> python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to
> python-chinese-request在lists.python.cn
> Detail Info:
> http://python.cn/mailman/listinfo/python-chinese
>
2007年03月08日 星期四 23:33
Object.extend(AjaxForm.prototype, { //extend 继承父类么? Object不像是子类名
> setdata: function(objs){ //成员 函数?
> $H(objs).each(function(k, v){
> $("[@name='$0']".template([k]), this.e).val(v);
> });
> return this;
> },
>
> hookajax: function(){
> .....................
> }
>
> });
Neil(木野狐) 写道:
> javascript 没有正式的"类"的说法,但是可以利用 function 来模拟类的一些简单行为。
>
> a = function(){
> alert('b');
> }
> 这种方式只是定义一个匿名函数,然后把它赋值给 a 这个变量。
> js 中模拟类编程的一个重要方法是用 prototype 的方式扩展。
>
> 在 07-3-8,Brightman<mr.brightman在gmail.com> 写道:
>
>> Brightman 写道:
>> ajax_form.js代码如下:我不大懂那些是类那些是类成员函数
>>
>> __data_handle = function(target, data){ //这是定 义一个类么?还是函数
>> var obj = target;
>> var e = obj.form;
>> //remove all error infos
>> $('.error', e).remove();
>> ............
>> }
>>
>> AjaxForm = function(form, options){ //这是定义一 个类么?还是函数
>> this.options = options || {};
>> this.form = $(form);
>> this.hookajax();
>> }
>>
>> Object.extend(AjaxForm.prototype, { //exten 继承父类么?
>> setdata: function(objs){ //成员 函数?
>> $H(objs).each(function(k, v){
>> $("[@name='$0']".template([k]), this.e).val(v);
>> });
>> return this;
>> },
>>
>> hookajax: function(){
>> .....................
>> }
>>
>> });
>>
>>
>> 在网上没找到合适的javascript class的教程,不大懂故来请教。谢谢!
>>
>>
>> _______________________________________________
>> python-chinese
>> Post: send python-chinese在lists.python.cn
>> Subscribe: send subscribe to
>> python-chinese-request在lists.python.cn
>> Unsubscribe: send unsubscribe to
>> python-chinese-request在lists.python.cn
>> Detail Info:
>> http://python.cn/mailman/listinfo/python-chinese
>>
>>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
-------------- 下一部分 --------------
一个HTML附件被移除...
URL: http://python.cn/pipermail/python-chinese/attachments/20070308/04ef6cfe/attachment-0001.htm
2007年03月08日 星期四 23:54
extend 不是关键字,只是一个普通的函数。你看 jBasicExt.js 中有 Object.extend 函数的定义:
/* basic functions */
Object.extend = function(obj, prop){
for(var i in prop) obj[i] = prop[i];
return obj;
};
这个函数的作用是将 prop 对象中的所有属性复制到 obj 中,也就是扩展了 obj 的内容。
下面的写法,其实是个普通的对象语法。
// js 里可以这样定义对象:
var o = new Object();
// 然后可以给它赋属性:
o.a = "hello";
alert(o.a);
// 这种写法和上面一行是等价的:
alert(o['a']);
// 当然属性值也可以是匿名函数
o.f = function(){
alert('test');
};
// 对象还有另一种定义方式,object literal. 大体相当于 python 的 dict.
var o2 = {
"a": 123,
"func1": function(x){
alert(x);
}
};
alert(o2['a']);
alert(o2.a);
alert(o2.func1);
alert(o2['func1']);
o2.func1('xyz');
这样你再看看原来那段代码是不是很好理解了。
在 07-3-8,Brightman<mr.brightman在gmail.com> 写道:
>
> Object.extend(AjaxForm.prototype, { //extend 继承父类么? Object不像是子类名
> > setdata: function(objs){ //成员 函数?
> > $H(objs).each(function(k, v){
> > $("[@name='$0']".template([k]), this.e).val(v);
> > });
> > return this;
> > },
> >
> > hookajax: function(){
> > .....................
> > }
> >
> > });
>
>
> Neil(木野狐) 写道:
> javascript 没有正式的"类"的说法,但是可以利用 function 来模拟类的一些简单行为。
>
> a = function(){
> alert('b');
> }
> 这种方式只是定义一个匿名函数,然后把它赋值给 a 这个变量。
> js 中模拟类编程的一个重要方法是用 prototype 的方式扩展。
>
> 在 07-3-8,Brightman<mr.brightman在gmail.com> 写道:
>
>
> Brightman 写道:
> ajax_form.js代码如下:我不大懂那些是类那些是类成员函数
>
> __data_handle = function(target, data){ //这是定 义一个类么?还是函数
> var obj = target;
> var e = obj.form;
> //remove all error infos
> $('.error', e).remove();
> ............
> }
>
> AjaxForm = function(form, options){ //这是定义一 个类么?还是函数
> this.options = options || {};
> this.form = $(form);
> this.hookajax();
> }
>
> Object.extend(AjaxForm.prototype, { //exten 继承父类么?
> setdata: function(objs){ //成员 函数?
> $H(objs).each(function(k, v){
> $("[@name='$0']".template([k]), this.e).val(v);
> });
> return this;
> },
>
> hookajax: function(){
> .....................
> }
>
> });
>
>
> 在网上没找到合适的javascript class的教程,不大懂故来请教。谢谢!
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to
> python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to
> python-chinese-request在lists.python.cn
> Detail Info:
> http://python.cn/mailman/listinfo/python-chinese
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to
> python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to
> python-chinese-request在lists.python.cn
> Detail Info:
> http://python.cn/mailman/listinfo/python-chinese
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to
> python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to
> python-chinese-request在lists.python.cn
> Detail Info:
> http://python.cn/mailman/listinfo/python-chinese
>
2007年03月09日 星期五 00:23
On 3/8/07, Brightman <mr.brightman在gmail.com> wrote: > > Brightman 写道: > ajax_form.js代码如下:我不大懂那些是类那些是类成员函数 > > __data_handle = function(target, data){ //这是定 义一个类么?还是函数 > var obj = target; > var e = obj.form; > //remove all error infos > $('.error', e).remove(); > ............ > } 这是一个公共函数,用在AjaxForm和AjaxIFrame中,因为处理一样,所以公共出来了。 > > AjaxForm = function(form, options){ //这是定义一 个类么?还是函数 > this.options = options || {}; > this.form = $(form); > this.hookajax(); > } 这是一个类,因为有this了。而且一般类的定义函数没有返回值。 > > Object.extend(AjaxForm.prototype, { //exten 继承父类么? > setdata: function(objs){ //成员 函数? > $H(objs).each(function(k, v){ > $("[@name='$0']".template([k]), this.e).val(v); > }); > return this; > }, > > hookajax: function(){ > ..................... > } > > }); > 向类中扩展一些方法。 > > 在网上没找到合适的javascript class的教程,不大懂故来请教。谢谢! > 在最近的啄木鸟社区会课的第二部分我讲了一些关于openbookplatform的的结构,其中谈到了这个js代码。只不过没有ppt,只能听录音。 http://www.woodpecker.org.cn:9081/classes/classes2007/070303_qxg/cpug_2007_03_03_li_2.ogg -- I like python! UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad My Blog: http://www.donews.net/limodou
Zeuux © 2025
京ICP备05028076号