prototype.js对象持久性 [英] prototype.js object persistance

查看:58
本文介绍了prototype.js对象持久性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用prototype.js创建了一个新类。在我完成

ajax.request之后,对this.myClassMethodorVariable的所有引用都将丢失。

ajax方法是否会破坏对象持久性?我是相当新的

OOP javascript所以可能(并且可能是)忽略了一些细节。

以下是我正在尝试做的逻辑。


// Javascript代码

var myClass = Class.create();

myClass.prototype = {

initialize:function(fm){

//静态变量

this.myMessage =''hello'';

this.myName =''Nick'';

this.frm = fm;

this.WSURL =''/ some / Server / script'';

this.frm.onSubmit =

this.submitForm.bindAsEventListener(this);

},

submitForm:function( evt){

var pars = myMessage;

var myAjax = new Ajax.Request(this.WSURL,{method:''get'',

参数:pars,onSuccess:this.myHandler});

},

myHandler:function(ajaxResponse){

this。 myMessage(ajaxResponse.responseText);

},

myMessage:function(str){

alert(str);

}

};


// HTML代码

< ; form name =" someForm" ID = QUOT; someForm"方法= QUOT;交" action =" ##">

< input type =" text" ID = QUOT;&会将myText QUOT; />

< input type =" submit"命名= [提交" value =" submit">

< / form>

< script> var testClass = new myClass(''someform'');< / script> ;

I''ve created a new class using prototype.js. After I make the
ajax.request all references to this.myClassMethodorVariable are lost.
Does the ajax method blow out the object persistance? I''m fairly new to
OOP javascript so could be (and probably am) overlooking some detail.
Below is the logic of what i''m trying to do.

//Javascript code
var myClass = Class.create();
myClass.prototype={
initialize: function(fm) {
//Static Variables
this.myMessage = ''hello'';
this.myName = ''Nick'';
this.frm = fm;
this.WSURL = ''/some/Server/script'';
this.frm.onSubmit =
this.submitForm.bindAsEventListener(this);
},
submitForm: function(evt) {
var pars = myMessage;
var myAjax = new Ajax.Request( this.WSURL, { method: ''get'',
parameters: pars, onSuccess: this.myHandler});
},
myHandler: function(ajaxResponse) {
this.myMessage(ajaxResponse.responseText);
},
myMessage: function(str) {
alert(str);
}
};

//HTML Code
<form name="someForm" id="someForm" method="post" action="##">
<input type="text" id="myText" />
<input type="submit" name="submit" value="submit">
</form>
<script>var testClass = new myClass(''someform'');</script>

推荐答案

bi *** ***@gmail.com 在2006年5月25日下午2:03发表以下内容:
bi******@gmail.com said the following on 5/25/2006 2:03 PM:
我使用prototype.js创建了一个新类。


上面有99.99999999%的问题。使用一个毫无价值的

垃圾脚本库。

在我创建ajax.request之后,所有对this.myClassMethodorVariable的引用都将丢失。
I''ve created a new class using prototype.js.
There above is 99.99999999% of your problem. Using a worthless piece of
junk script library.
After I make the ajax.request all references to this.myClassMethodorVariable
are lost.




停止使用prototype.js,你不再有问题了。


为什么人们来这里寻求帮助一个特定的图书馆

去找那个写这个图书馆的无能的程序员?


-

兰迪

comp.lang.javascript常见问题 - http://jibbering.com/faq &安培;新闻组每周

Javascript最佳实践 - http://www.JavascriptToolbox .com / bestpractices /



Stop using prototype.js, you don''t have an issue with it anymore.

Why do people come here asking for help with a specific library instead
of going to the inept programmer who wrote that library?

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


>>为什么人们来这里寻求特定图书馆的帮助呢

of去找那个编写那个库的无能的程序员?


哇这对编程社区是一个有用的贡献。


我知道没有人怎么样开发任何图书馆,我们都需要2个月

来完成2天内可以完成的任务。


更好,让我们完全抵制javascript,毕竟一些不合格的程序员写的很多



>>Why do people come here asking for help with a specific library instead
of going to the inept programmer who wrote that library?

wow that was a useful contribution to the programming community.

I know how about nobody develops any libraries and we all take 2 months
to accomplish what can be done in 2 days.

better yet, lets boycott javascript altogether, after all it was prolly
written by some inept programmer.


别误会我的意思我还是不认为这是要求的地方帮助

和其他图书馆一样,他们应该拥有自己的团队,如果他们不这样做,那么
就有一个非常容易制作一个。 (这就是我为

scriptaculous而做的事情)


但是对于那些不太称为thsoe库的程序员而言,这是不公平的,它的价值是多少美元b通常使用控制权的人是无能为力的。

Dont get me wrong I still dont think this is the place to ask for help
with other libraries they should have there own group and if they dont
have one its pretty easy to make one. (thats what I did for
scriptaculous anyway)

But its not fair to call the programmers of thsoe libraries inept, its
usally the person using the control who is inept.


这篇关于prototype.js对象持久性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆