EzDevInfo.com

properties interview questions

Top properties frequently asked interview questions

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.


Source: (StackOverflow)

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? It 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 provide a magic __count__ property, but this was removed somewhere around version 4.)


Source: (StackOverflow)

Advertisements

What does the property "Nonatomic" mean?

What does "nonatomic" mean in this code?

@property(nonatomic, retain) UITextField *theUsersName;

What is the difference between atomic and nonatomic?

Thanks


Source: (StackOverflow)

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 these three?


Source: (StackOverflow)

Sort array of objects by string property value in JavaScript

I have an array of JavaScript objects:

var objs = [ 
    { first_nom: 'Lazslo', last_nom: 'Jamf'     },
    { first_nom: 'Pig',    last_nom: 'Bodine'   },
    { first_nom: 'Pirate', last_nom: 'Prentice' }
];

How can I sort them by the value of last_nom in JavaScript?

I know about sort(a,b), but that only seems to work on strings and numbers. Do I need to add a toString method to my objects?


Source: (StackOverflow)

Objective-C ARC: strong vs retain and weak vs assign

There are two new memory management attributes for properties introduced by ARC, strong and weak.

Apart from copy, which is obviously something completely different, are there any differences between strong vs retain and weak vs assign?

From my understanding, the only difference here is that weak will assign nil to the pointer, while assign won't, which means the program will crash when I send a message to the pointer once it's been released. But if I use weak, this won't ever happen, because message send to nil won't do anything.

I don't know about any differences between strong and retain.

Is there any reason why should I use assign and retain in new projects, or are the kind of being deprecated?


Source: (StackOverflow)

Semantic Issue: Property's synthesized getter follows Cocoa naming convention for returning 'owned' objects

I'm currently using the iOS 5 SDK trying to develop my app. I'm trying to make an NSString a property, and then to synthesize it in the .m file (I have done this before with no issues). Now, I came across this: "Semantic Issue: Property's synthesized getter follows Cocoa naming convention for returning 'owned' objects."

This is my code: .h

@interface ViewController : UIViewController {
     NSString *newTitle;
}
@property (strong, nonatomic) NSString *newTitle;

.m

@synthesize newTitle;

Does anyone have a clue how I could fix this? Thanks!!


Source: (StackOverflow)

How does the @property decorator work?

I would like to understand how the built-in function property works. The confusing part for me is that property can be a decorator as well while it does not have arguments for decorating a function.

This example is from the documentation:

class C(object):
    def __init__(self):
        self._x = None

    def getx(self):
        return self._x
    def setx(self, value):
        self._x = value
    def delx(self):
        del self._x
    x = property(getx, setx, delx, "I'm the 'x' property.")

property's arguments are getx, setx, delx and a doc string.

In the code below property is used as decorator. The object of it is the x function, but in the code above there is no place for an object function in the arguments.

class C(object):
    def __init__(self):
        self._x = None

    @property
    def x(self):
        """I'm the 'x' property."""
        return self._x

    @x.setter
    def x(self, value):
        self._x = value

    @x.deleter
    def x(self):
        del self._x

And, how are the x.setter and x.deleter decorators created? I am confused.


Source: (StackOverflow)

How to get the list of properties of a class?

How do I get a list of all the properties of a class?


Source: (StackOverflow)

Public Fields versus Automatic Properties

We're often told we should protect encapsulation by making getter and setter methods (properties in C#) for class fields, instead of exposing the fields to the outside world.

But there are many times when a field is just there to hold a value and doesn't require any computation to get or set. For these we would all do this number:

public class Book
{
    private string _title;

    public string Title
    {
          get{ return _title;  }
          set{ _title = value; }
    }
}

Well, I have a confession, I couldn't bear writing all that (really, it wasn't having to write it, it was having to look at it), so I went rogue and used public fields.

Then along comes C# 3.0 and I see they added automatic properties:

public class Book
{
    public string Title {get; set;} 
}

which is tidier, and I'm thankful for it, but really, what's so different than just making a public field?

public class Book
{
    public string Title;
}

Source: (StackOverflow)

Sorting JavaScript Object by property value

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": 116};

I'm having a real brain-dead moment regarding this.


Source: (StackOverflow)

Dynamically access object property using variable

I'm trying to access a property of an object using a dynamic name. Is this possible?

something = { bar: "Foobar!" }
foo = 'bar'
something.foo // The idea is to access something.bar, getting "Foobar!"

Source: (StackOverflow)

How to use Java property files?

So I have a list of key/value pairs of configuration values I want to store as Java property files, and later load and iterate through.

Questions:

  • Do I need to store the file in the same package as the class which will load them, or is there any specific location where it should be placed?
  • Does the file need to end in any specific extension or is .txt OK?
  • How can I load the file in the code
  • And how can I iterate through the values inside?

Source: (StackOverflow)

Set object property using reflection

Is there a way in .NET c# 3.5 I can use reflection to set an object property?

Ex:

MyObject obj = new MyObject();
obj.Name = "MyName";

I want to set obj.Name with reflection. Something like:

Reflection.SetProperty(obj, "Name") = "MyName";

Is there a way of doing this?


Source: (StackOverflow)

Shortcut to create properties in Visual Studio?

I have seen some people creating properties in C# really fast, but how they dod it?

What shortcuts are available in Visual Studio (currently using Visual Studio 2010) to create properties?

I am using C#.

For example,

public string myString {get;set;}

Source: (StackOverflow)