Skip to content

K33TY/Funsies

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Happy Code-y Things Go Here

I love code reflection.

Why?

Reflection allows you to modify and inspect objects at runtime.

A year ago, I discovered reflection during my internship. Though, I don't remember how I came across reflection. (It may have been because I was playing around with ILSpy at the time.) One of my coworkers was painstakingly trying to hardcode several pages worth of field names to their respective values, but I replaced it with a few lines of code. The best part was, when the objects were renamed or altered, our code did not need to be changed. It could grab all the field names from the object, and then use those for headers of a datagrid, and then fill the values in for all the objects in the list.

Brilliant.

Today I found out that JavaScript also utilizes reflection ♥

Here I was, staring at a large JSON file and feeling disgusted at the idea of mapping out each property one by one to a list of objects, when, I remembered reflection.

Oh reflection, you wonderful thing, you.

  response.data.items.forEach(function (i) {
       var node = {id:i.id,title:i.title};
       i.subitems.forEach(function(property) {
           node[property] = i.subitems[property]; 
       })
     });

Magic.

Releases

No releases published

Packages

No packages published