Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a descriptor? [closed]

Tags:

The method Object.defineProperty (see here) accepts as third argument a "descriptor".

What is a descriptor?

like image 876
Randomblue Avatar asked Feb 06 '12 20:02

Randomblue


People also ask

Do I need to close a file descriptor?

Yes, close your file descriptors and free all heap memory, even if you know that the OS will clean it up - that way, when you run valgrind or some similar tool, you don't get a lot of noise in the results, and you can easily recognize "legit" fd leaks.

What happens if you don't close descriptor?

As long as your program is running, if you keep opening files without closing them, the most likely result is that you will run out of file descriptors/handles available for your process, and attempting to open more files will fail eventually.

What is a file descriptor example?

A file descriptor is a number that uniquely identifies an open file in a computer's operating system. It describes a data resource, and how that resource may be accessed. When a program asks to open a file — or another data resource, like a network socket — the kernel: Grants access.

How do you close a socket descriptor?

The close() function closes a descriptor, fildes. This frees the descriptor to be returned by future open() calls and other calls that create descriptors. When the last open descriptor for a file is closed, the file itself is closed.


2 Answers

A property descriptor can be of two types: data descriptor, or accessor descriptor.

Data descriptor

Mandatory properties:

  • value

Optional properties:

  • configurable
  • enumerable
  • writable

Sample:

{     value: 5,     writable: true } 

Accessor descriptor

Mandatory properties:

  • Either get or set or both

Optional properties:

  • configurable
  • enumerable

Sample:

{     get: function () {         return 5;     },     enumerable: true } 
like image 179
Domenic Avatar answered Sep 22 '22 14:09

Domenic


A descriptor is something that describes something. In this case it's just a plain object ({...}) with certain fields, that describes how the property should behave. Read further down the page to see what fields you can use.

like image 26
Matti Virkkunen Avatar answered Sep 25 '22 14:09

Matti Virkkunen