如何动态扩展javascript对象? [英] How do I dynamically extend javascript objects?

查看:54
本文介绍了如何动态扩展javascript对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





对不起我的术语在这里失败了。我很确定这是我无法找到答案的原因(或者当我知道答案时没有认出有效的答案)



我正在写一个基于网络的使用SignalR的应用程序。将有许多(大约350个)运营商使用该系统,我需要传达数据变化以及数据锁(没有两个运营商可以打开相同的记录进行编辑,例如)。



我有几个需要连接的控件,所以我正在尝试管理一个可以包含在脚本管理器中的单个共享连接脚本。



启动很简单:

Hi,

Sorry if my terminology fails me, here. I pretty sure it's the reason I can't find an answer (or didn't recognize a valid answer when I had fount it)

I am writing a web based application using SignalR. There will be many (around 350) operators using the system and I need to communicate data changes, as well as data locks (no two operators can have the same record open for edit for eg).

I have several controls that require the connection, so I'm trying to manage a single shared connection script I can include with the script manager.

The startup is simple enough:

var hubPromise, connection, signalrStartDoneFunctions = [];

// function in StartupFunctions are called on doc.ready (and after partial postbacks)
StartupFunctions.push(function () {

	connection = $.connection.adminServicesHub;

	//Used to confirm that the connection is open
    hubPromise = connection.hub;

    hubPromise.start().done(function () {
    	//signalrStartDoneFunctions contains function that, unlike StartupFunctions, require the singlar connection to be started
		$.each(signalrStartDoneFunctions, function () {
			this();
		});
	});
});





我声明客户端功能的方式是jQuery.extend:





The way I have declared client-side functions is with jQuery.extend:

$.extend(connection.client, {
    pulseNewUserPanel: pulseNewUserPanelClient,
    pulseExistingUserPanel: pulseExistingUserPanelClient
}





我希望能够为每个控件声明这些。每个控件实例都应该有自己的功能来添加。



管理这个的最佳方法是什么?理想情况下,我想确保它们在 connection.hub.start()之前存在。这样我就可以在启动时执行一些检查并在需要时提醒客户端。



我可以通过数组设置这些,就像启动功能一样吗?任何意见将是有益的。到目前为止,我已经得到了谷歌的所有答案:S



谢谢^ _ ^

Andy



I want to be able to declare these per control too. Each instance of the controls should have it's own functions to add.

What is the best way to manage this? Ideally I would like to ensure that they are there before connection.hub.start(). That way I can perform some checks on startup and alert the client if I need to.

Can I set these up via an array as I do with the startup functions? Any advice would be helpful. Up until this point I've pretty much got all my answers from google :S

Thanks ^_^
Andy

推荐答案

.connection.adminServicesHub;

// 用于确认连接已打开
hubPromise = connection.hub;

hubPromise.start()。done( function (){
// signalrStartDoneFunctions包含的函数与StartupFunctions不同,需要启动单一连接
.connection.adminServicesHub; //Used to confirm that the connection is open hubPromise = connection.hub; hubPromise.start().done(function () { //signalrStartDoneFunctions contains function that, unlike StartupFunctions, require the singlar connection to be started


.each(signalrStartDoneFunctions,< span class =code-keyword> function (){
this ();
});
});
});
.each(signalrStartDoneFunctions, function () { this(); }); }); });





我声明客户端函数的方式是使用jQuery.extend:





The way I have declared client-side functions is with jQuery.extend:


.extend(connection.client,{
pulseNewUserPanel:pulseNewUserPanelClient,
pulseExistingUserPanel:pulseExistingUserPanelClient
}
.extend(connection.client, { pulseNewUserPanel: pulseNewUserPanelClient, pulseExistingUserPanel: pulseExistingUserPanelClient }





我希望能够为每个控件声明这些。每个实例控件应该有它自己的功能来添加。



管理它的最佳方法是什么?理想情况下我想确保它们在那之前 connection.hub.start()。这样我可以在启动时执行一些检查,并在需要时提醒客户端。



我可以像启动函数一样通过数组设置这些吗?任何建议都会有所帮助。到目前为止,我已经得到了谷歌的所有答案:S



谢谢^ _ ^

Andy



I want to be able to declare these per control too. Each instance of the controls should have it's own functions to add.

What is the best way to manage this? Ideally I would like to ensure that they are there before connection.hub.start(). That way I can perform some checks on startup and alert the client if I need to.

Can I set these up via an array as I do with the startup functions? Any advice would be helpful. Up until this point I've pretty much got all my answers from google :S

Thanks ^_^
Andy


这篇关于如何动态扩展javascript对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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