Questions tagged [properties]

A property, in some object-oriented programming languages, is a special sort of class member, intermediate between a field (or data member) and a method. Properties are read and written like fields, but property reads and writes are (usually) translated to get and set method calls.

Property, in some object-oriented programming languages, is a special sort of class member, intermediate between a field (or data member) and a method.

Properties are read and written like fields, but property reads and writes are (usually) translated to get and set method calls. The field-like syntax is said to be easier to read and write than lots of method calls, yet the interposition of method calls allows for data validation, active updating (as of GUI visuals), or read-only 'fields'. That is, properties are intermediate between member code (methods) and member data (instance variables) of the class, and properties provide a higher level of encapsulation than public fields.

See:

18121 questions
7395
votes
38 answers

How do I remove a property from a JavaScript object?

Given an object: let myObject = { "ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*" }; How do I remove the property regex to end up with the following myObject? let myObject = { "ircEvent": "PRIVMSG", "method": "newURI" };
johnstok
  • 96,212
  • 12
  • 54
  • 76
1968
votes
20 answers

How to efficiently count the number of keys/properties of an object in JavaScript

What's the fastest way to count the number of keys/properties of an object? Is it possible to do this without iterating over the object? I.e., without doing: var count = 0; for (k in myobj) if (myobj.hasOwnProperty(k)) ++count; (Firefox did…
mjs
  • 63,493
  • 27
  • 91
  • 122
1942
votes
28 answers

What's the difference between the atomic and nonatomic attributes?

What do atomic and nonatomic mean in property declarations? @property(nonatomic, retain) UITextField *userName; @property(atomic, retain) UITextField *userName; @property(retain) UITextField *userName; What is the operational difference between…
Alex Wayne
  • 178,991
  • 47
  • 309
  • 337
1505
votes
33 answers

What is the difference between a field and a property?

In C#, what makes a field different from a property, and when should a field be used instead of a property?
Anonymous
1333
votes
15 answers

How does the @property decorator work in Python?

I would like to understand how the built-in function property works. What confuses me is that property can also be used as a decorator, but it only takes arguments when used as a built-in function and not when used as a decorator. This example is…
ashim
  • 24,380
  • 29
  • 72
  • 96
1167
votes
24 answers

Get property value from string using reflection

I am trying implement the Data transformation using Reflection1 example in my code. The GetSourceValue function has a switch comparing various types, but I want to remove these types and properties and have GetSourceValue get the value of the…
pedrofernandes
  • 16,354
  • 10
  • 36
  • 43
991
votes
45 answers

Sorting object property by values

If I have a JavaScript object such as: var list = { "you": 100, "me": 75, "foo": 116, "bar": 15 }; Is there a way to sort the properties based on value? So that I end up with list = { "bar": 15, "me": 75, "you": 100, "foo":…
Steerpike
  • 17,163
  • 8
  • 39
  • 53
960
votes
19 answers

Accessing an object property with a dynamically-computed name

I'm trying to access a property of an object using a dynamic name. Is this possible? const something = { bar: "Foobar!" }; const foo = 'bar'; something.foo; // The idea is to access something.bar, getting "Foobar!"
RichW
  • 10,692
  • 6
  • 26
  • 33
937
votes
6 answers

Does C# have extension properties?

Does C# have extension properties? For example, can I add an extension property to DateTimeFormatInfo called ShortDateLongTimeFormat which would return ShortDatePattern + " " + LongTimePattern?
Svish
  • 152,914
  • 173
  • 462
  • 620
867
votes
64 answers

Test for existence of nested JavaScript object key

If I have a reference to an object: var test = {}; that will potentially (but not immediately) have nested objects, something like: {level1: {level2: {level3: "level3"}}}; What is the best way to check for the existence of property in deeply…
user113716
  • 318,772
  • 63
  • 451
  • 440
796
votes
13 answers

Using @property versus getters and setters

What advantages does the @property notation hold over the classic getter+setter? In which specific cases/situations should a programmer choose to use one over the other? With properties: class MyClass(object): @property def my_attr(self): …
Zaur Nasibov
  • 22,280
  • 12
  • 56
  • 83
770
votes
11 answers

How to get the list of properties of a class?

How do I get a list of all the properties of a class?
Sukesh
722
votes
14 answers

How do I enumerate the properties of a JavaScript object?

How do I enumerate the properties of a JavaScript object? I actually want to list all the defined variables and their values, but I've learned that defining a variable actually creates a property of the window object.
davenpcj
  • 12,508
  • 5
  • 40
  • 37
584
votes
16 answers

How to use a variable for a key in a JavaScript object literal?

Why does the following work? .stop().animate( { 'top' : 10 }, 10 ); Whereas this doesn't work: var thetop = 'top'; .stop().animate( { thetop : 10 }, 10 ); To make it even clearer: At the moment I'm not able to pass a…
speendo
  • 13,045
  • 22
  • 71
  • 107
578
votes
7 answers

What is the difference between properties and attributes in HTML?

After the changes made in jQuery 1.6.1, I have been trying to define the difference between properties and attributes in HTML. Looking at the list on the jQuery 1.6.1 release notes (near the bottom), it seems one can classify HTML properties and…
schalkneethling
  • 6,327
  • 3
  • 21
  • 20
1
2 3
99 100