instance

offline, cross-tab communication (javascript-only)

心不动则不痛 提交于 2019-12-01 01:35:57
Is it possible to find foreign instances of certain website? Ofc theese are independently opened tabs (not by window.open). I need to prevent user from opening 2 tabs, and send message to previously opened tab to inform that it's impossible to open 2 tabs. 2 Intependent tabs may break page offline storage and webSQL structure, so that I can't allow people to use 2 tabs. It's also semi-offline app so it needs to be client-side solution. You can communicate across tabs using localStorage. Every time you write a value, a "storage" event is fired on the window object on every tab (except the

How to get the instance of the currently visible fragment in ViewPager:

ぐ巨炮叔叔 提交于 2019-12-01 00:22:37
I'm building an application that shows different fragments in a ViewPager . I add these fragments to the ViewPager like this: public void intialiseViewPager() { List<Fragment> fragments = new Vector<Fragment>(); numberOfTabs = application.currentReport.getODTabsList().size(); for (int i = 0; i < numberOfTabs; i++) { ODTab tempTab = application.currentReport.getODTabsList().get(i); if (tempTab.getTabType().equals(ODGrid.XML_GRID_ELEMENT)) { GridFragment gridFragment = GridFragment.newInstance(tempTab.getTabId()); fragments.add(gridFragment); } else if (tempTab.getTabType().equals(ODChart.XML

Members vs method arguments access in C++

你离开我真会死。 提交于 2019-12-01 00:14:59
Can I have a method which takes arguments that are denoted with the same names as the members of the holding class? I tried to use this: class Foo { public: int x, y; void set_values(int x, int y) { x = x; y = y; }; }; ... but it doesn't seem to work. Is there any way of accessing the the instance the namespace of which I'm working in, similar to JavaScript's this or Python's self ? It's generally a good idea to avoid this kind of confusion by using a naming convention for member variables. For example, camelCaseWithUnderScore_ is quite common. That way you would end up with x_ = x; , which is

How does an enum singleton function?

爱⌒轻易说出口 提交于 2019-11-30 23:29:55
Previously instead of using enums, I would do something like: public static ExampleClass instance; public ExampleClass(){ instance=this; } public static ExampleClass getInstance(){ return instance; } Then someone told me about a enum singleton: public enum Example{ INSTANCE; public static Example getInstance(){ return Example.INSTANCE; } In the first example I had to instantiate the object in order to create the instance. With an enum, I do not need to do that.. at least it appears. Can someone explain the reason behind this? The Java compiler takes care of creating enum fields as static

Access parent class instance attribute from child class instance?

≡放荡痞女 提交于 2019-11-30 23:15:24
问题 How to access "myvar" from "child" in this code example: class Parent(): def __init__(self): self.myvar = 1 class Child(Parent): def __init__(self): Parent.__init__(self) # this won't work Parent.myvar child = Child() 回答1: Parent is a class - blue print not an instance of it, in OOPS to access attributes of an object it requires instance of the same, Here self/child is instance while Parent/Child are classes... see the answer below, may clarify your doubts. class Parent(): def __init__(self):

offline, cross-tab communication (javascript-only)

☆樱花仙子☆ 提交于 2019-11-30 20:50:15
问题 Is it possible to find foreign instances of certain website? Ofc theese are independently opened tabs (not by window.open). I need to prevent user from opening 2 tabs, and send message to previously opened tab to inform that it's impossible to open 2 tabs. 2 Intependent tabs may break page offline storage and webSQL structure, so that I can't allow people to use 2 tabs. It's also semi-offline app so it needs to be client-side solution. 回答1: You can communicate across tabs using localStorage.

In Java, why can't a super-class method access protected or private methods/variables from a sub-class instance?

删除回忆录丶 提交于 2019-11-30 20:04:56
Let's start with another behavior: even if you declare a method/variable as private, another instance of the same class can access it. That's OK I can live with it. I call these class-private and not instance-private. Now the question part: For example, at runtime I want to be able to check that all String variables in this class are not null, and if they are null they should be changed to the string "NULL". I can run through the variables using reflection and get their values. But if I extend my class and add private or even protected variables my base class can't access them. I have to

How to get the instance of the currently visible fragment in ViewPager:

自作多情 提交于 2019-11-30 19:12:45
问题 I'm building an application that shows different fragments in a ViewPager . I add these fragments to the ViewPager like this: public void intialiseViewPager() { List<Fragment> fragments = new Vector<Fragment>(); numberOfTabs = application.currentReport.getODTabsList().size(); for (int i = 0; i < numberOfTabs; i++) { ODTab tempTab = application.currentReport.getODTabsList().get(i); if (tempTab.getTabType().equals(ODGrid.XML_GRID_ELEMENT)) { GridFragment gridFragment = GridFragment.newInstance

How does an enum singleton function?

*爱你&永不变心* 提交于 2019-11-30 18:06:00
问题 Previously instead of using enums, I would do something like: public static ExampleClass instance; public ExampleClass(){ instance=this; } public static ExampleClass getInstance(){ return instance; } Then someone told me about a enum singleton: public enum Example{ INSTANCE; public static Example getInstance(){ return Example.INSTANCE; } In the first example I had to instantiate the object in order to create the instance. With an enum, I do not need to do that.. at least it appears. Can

Global instances of class

我的梦境 提交于 2019-11-30 15:51:05
Still trying to get to know C# (Mostly worked with C). I have a class "Device" and would like to create an instance of the class, but would also like access to the instances globally because I use them so much in my GUI methods. public class Device { public string Name; public List<string> models = new List<string>(); public List<string> revisions = new List<string>(); ... } Somehow declare this globally: Device Device1 = new Device(); Device1.Name = "Device1"; Then access it later in a WPF method: private void DeviceViewItem_Selected(object sender, RoutedEventArgs e) { TreeViewItem selected =