instance

Difference between reference and instance in javascript

你说的曾经没有我的故事 提交于 2019-11-29 22:35:26
Sometimes I hear people say "a reference to a object" and some say "a instance of a object" What is the difference? A variable will hold a reference to an instance of an object. The actual object is an instance . The variable/variables used to access the object hold the references to it. Instance of an object (or, perhaps more accurately phrased when talking about languages that have the notion, of a class) is an object that has been created and exists in memory. For example, when writing var obj = new Foo(); Then a new instance of an object has been created (with new Foo ). Reference to an

SQLAlchemy: Modification of detached object

让人想犯罪 __ 提交于 2019-11-29 22:24:35
I want to duplicate a model instance (row) in SQLAlchemy using the orm. My first thought was to do this: i = session.query(Model) session.expunge(i) old_id = i.id i.id = None session.add(i) session.flush() print i.id #New ID However, apparently the detached object still "remembers" what id it had, even though I set the id to None while it was detached. Thus, session.flush() tries to execute an UPDATE changing the primary key to null. Is this expected behavior? How can I remove the 'memory' of this attribute, and just treat the detached object as a new object upon re-adding it to the session?

WPF Enforce only ONE instance of application

柔情痞子 提交于 2019-11-29 20:55:47
How do I allow only one instance of a WPF application to run? Thanks. http://blogs.microsoft.co.il/blogs/arik/archive/2010/05/28/wpf-single-instance-application.aspx Doesn't require VB.DLL as some other examples advise. Has WPF sample code. Passes any cmd line args to initial instance. Try this: Single instance application . Ive used the second method and it works fine. I use this helper method and call it from the application.startup event Public Sub ForceSingleInstanceApplication() 'Get a reference to the current process Dim MyProc As Process = Process.GetCurrentProcess 'Check how many

Starting multiple upstart instances automatically

╄→гoц情女王★ 提交于 2019-11-29 19:53:46
We use PHP gearman workers to run various tasks in parallel. Everything works just fine, and I have silly little shell script to spin them up when I want them. Being a programmer (and therefore lazy), I wanted to see if I could spin these up via an upstart script. I figured out how to use the instance stanza, so I could start them with an instance number: description "Async insert workers" author "Mike Grunder" env SCRIPT_PATH="/path/to/my/script" instance $N script php $SCRIPT_PATH/worker.php end script And this works great, to start them like so: sudo start async-worker N=1 sudo start async

V8 FunctionTemplate Class Instance

时光总嘲笑我的痴心妄想 提交于 2019-11-29 19:14:28
问题 I have the following class: class PluginManager { public: Handle<Value> Register(const Arguments& args); Handle<ObjectTemplate> GetObjectTemplate(); }; I want the Register method to be accessible from JavaScript. I add it to the global object like this: PluginManager pluginManagerInstance; global->Set(String::New("register"), FunctionTemplate::New(pluginManagerInstance.Register)); It throws the following error: 'PluginManager::Register': function call missing argument list; use '

Appending el in Backbone from an instance

末鹿安然 提交于 2019-11-29 18:13:37
I'm attempting to append the html within el from instances var Article1 = Backbone.View.extend({ initialize: function(options) { console.log('type 1', options) this.flyIn(options); }, flyIn: function(options) { this.$el.find('.superDog').css({ display: 'block' }); this.$el.find('.superDog').animate({ top: options.top, left: options.left }, 3000); }, render: function() { }, el: '<div><p class="superDog"></p></div>' }); var Article1A = new Article1({ color: 'black', top: '300', left: '300', html: 'hello world' }); var Article1B = new Article1({ color: 'blue', top: '800', left: '800', html:

All instances of a class have the same dict as an attribute in Python 3.2

99封情书 提交于 2019-11-29 18:06:02
I'm writing a space trading game in Python, and I've decided that the map needs to be split into smaller chunks to reduce the number of objects that need to be considered for drawing on the screen at any given time. This is handled by having a Sector object, which is defined as such: class Sector: x=0 #Position of the sector. The galactic (absolute) position of any object is its in-sector position y=0 #plus the galactic position offset times the size of a sector. stardict=dict() Then, the generator code populates each sector (100 of them at the moment) with 75 stars, kept in stardict.

Is there no standard (Either a) monad instance?

拥有回忆 提交于 2019-11-29 17:32:21
问题 I was under the impression that there was an instance for Either a somewhere, but I can't seem to find it. I have tried importing Control.Monad, Control.Monad.Instances and Data.Either as shown module Main where import Control.Monad import Data.Either import Control.Monad.Instances test :: [Either a b] -> Either a [b] test = sequence main = return () but ghc tells me that it could not deduce (Monad (Either a)). Adding instance Monad (Either a) where return = Right Right b >>= f = f b Left a >

How to create a new instance of a struct in C

被刻印的时光 ゝ 提交于 2019-11-29 17:23:30
问题 In C, when you define a struct. What is the correct way to create a new instance? I've seen two ways: struct listitem { int val; char * def; struct listitem * next; }; The first way (xCode says this is redefining the struct and wrong): struct listitem* newItem = malloc(sizeof(struct listitem)); The second way: listitem* newItem = malloc(sizeof(listitem)); Alternatively, is there another way? 回答1: The second way only works if you used typedef struct listitem listitem; before any declaration of

How to call a method of another Class?

五迷三道 提交于 2019-11-29 15:56:47
EDIT2: I try to summarize my problem and the solutions: I've got a TableViewController named DetailedViewController. My intention was to activate TouchesBegan to recognize actions like sliding etc, and normally, the method touchesbegan is replaced with the DidSelectRow method. In many posts on stackoverflow, subclassing the UITableView is the only possibility to realize this. So i created a SpecificTable with .xib file and i used this as a subclass of UITableViewController by adding the SpecificTable as the nib-file. Selecting a row works fine, and also the TouchesBegan method (i called a