Questions tagged [object]

An object is any entity that can be manipulated by commands in a programming language. An object can be a value, a variable, a function, or a complex data-structure. In object-oriented programming, an object refers to an instance of a class.

Objects in object-oriented programming (OOP) are data structures combined with the associated processing routines. Classes are sets of objects, while objects are instances of sets. Objects have members and methods, defining their properties and their abilities. Classes can have their own members and methods, which define the properties and abilities of the set of objects. For instance, if we have a Bird class, its objects might have an age property and a fly ability, while the Bird class might have a number of birds or a migrate ability, which is applicable for the set. Class-level methods are called static, or shared. For instance, a file could be represented as an object: a collection of data and the associated read and write routines. In typical object-oriented languages, all objects are instances of classes.

Properties of an object

Three properties characterize objects:

  • Identity: the property of an object that distinguishes it from other objects
  • State: describes the data stored in the object
  • Behavior: describes the methods in the object's interface by which the object can be used

See also:

  • (Used as a template for creating new objects)
  • (Object-oriented programming)

Resource

64898 questions
234
votes
4 answers

super() fails with error: TypeError "argument 1 must be type, not classobj" when parent does not inherit from object

I get some error that I can't figure out. Any clue what is wrong with my sample code? class B: def meth(self, arg): print arg class C(B): def meth(self, arg): super(C, self).meth(arg) print C().meth(1) I got the sample…
Ehsan Foroughi
  • 3,010
  • 2
  • 18
  • 20
232
votes
10 answers

PHP check whether property exists in object or class

I understand PHP does not have a pure object variable, but I want to check whether a property is in the given object or class. $ob = (object) array('a' => 1, 'b' => 12); or $ob = new stdClass; $ob->a = 1; $ob->b = 2; In JS, I can write this to…
Micah
  • 4,254
  • 8
  • 30
  • 38
230
votes
4 answers

Creating a copy of an object in C#

Please have a look at the code below (excerpt from a C# book): public class MyClass { public int val; } public struct myStruct { public int val; } public class Program { private static void Main(string[] args) { MyClass…
afaolek
  • 8,452
  • 13
  • 45
  • 60
227
votes
12 answers

What is the difference between `new Object()` and object literal notation?

What is the difference between this constructor-based syntax for creating an object: person = new Object() ...and this literal syntax: person = { property1 : "Hello" }; It appears that both do the same thing, although JSLint prefers you use…
ectype
  • 14,865
  • 5
  • 21
  • 28
226
votes
6 answers

make arrayList.toArray() return more specific types

So, normally ArrayList.toArray() would return a type of Object[]....but supposed it's an Arraylist of object Custom, how do I make toArray() to return a type of Custom[] rather than Object[]?
kamikaze_pilot
  • 14,304
  • 35
  • 111
  • 171
226
votes
8 answers

How can a JavaScript object refer to values in itself?

Lets say I have the following JavaScript: var obj = { key1 : "it ", key2 : key1 + " works!" }; alert(obj.key2); This errors with "key1 is not defined". I have tried this.key1 this[key1] obj.key1 obj[key1] this["key1"] obj["key1"] and they never…
Erin Drummond
  • 5,347
  • 6
  • 35
  • 41
223
votes
5 answers

Which characters are valid/invalid in a JSON key name?

Are there any forbidden characters in key names, for JavaScript objects or JSON strings? Or characters that need to be escaped? To be more specific, I'd like to use "$", "-" and space in key names.
Christophe
  • 27,383
  • 28
  • 97
  • 140
223
votes
13 answers

How to find entry by object property from an array of objects?

The array looks like: [0] => stdClass Object ( [ID] => 420 [name] => Mary ) [1] => stdClass Object ( [ID] => 10957 [name] => Blah ) ... And I have an integer…
Alex
  • 66,732
  • 177
  • 439
  • 641
223
votes
14 answers

Find and remove objects in an array based on a key value in JavaScript

I have been trying several approaches on how to find an object in an array, where ID = var, and if found, remove the object from the array and return the new array of objects. Data: [ {"id":"88","name":"Lets go testing"}, …
Tom
  • 3,717
  • 5
  • 26
  • 28
222
votes
12 answers

Accessing Object Memory Address

When you call the object.__repr__() method in Python you get something like this back: <__main__.Test object at 0x2aba1c0cf890> Is there any way to get a hold of the memory address if you overload __repr__(), other then calling super(Class,…
thr
  • 19,160
  • 23
  • 93
  • 130
218
votes
7 answers

Add property to an array of objects

I have an array of objects as shown below Object {Results:Array[2]} Results:Array[2] [0-1] 0:Object id=1 name: "Rick" 1:Object id=2 name:'david' I want to add one more property named Active to each element…
Patrick
  • 3,938
  • 6
  • 20
  • 32
214
votes
16 answers

Parse JSON String into a Particular Object Prototype in JavaScript

I know how to parse a JSON String and turn it into a JavaScript Object. You can use JSON.parse() in modern browsers (and IE9+). That's great, but how can I take that JavaScript Object and turn it into a particular JavaScript Object (i.e. with a…
BMiner
  • 16,669
  • 12
  • 53
  • 53
211
votes
10 answers

Multiple arguments vs. options object

When creating a JavaScript function with multiple arguments, I am always confronted with this choice: pass a list of arguments vs. pass an options object. For example I am writing a function to map a nodeList to an array: function map(nodeList,…
Christophe
  • 27,383
  • 28
  • 97
  • 140
210
votes
24 answers

How to get the difference between two arrays of objects in JavaScript

I have two result sets like this: // Result 1 [ { value: "0", display: "Jamsheer" }, { value: "1", display: "Muhammed" }, { value: "2", display: "Ravi" }, { value: "3", display: "Ajmal" }, { value: "4", display: "Ryan" } ] //…
BKM
  • 6,949
  • 7
  • 30
  • 45
208
votes
13 answers

Getting the object's property name

I was wondering if there was any way in JavaScript to loop through an object like so. for(var i in myObject) { // ... } But get the name of each property like this. for(var i in myObject) { separateObj[myObject[i].name] = myObject[i]; } I…
Olical
  • 39,703
  • 12
  • 54
  • 77