I need to declare a lot of object properties in my script and I wonder if the're any way to shorten this:
Core.registry.taskItemSelected;
Core.registry.taskItemSelected.id;
Core.registry.taskItemSelected.name;
Core.registry.taskItemSelected.parent;
Core.registry.taskItemSelected.summary;
Core.registry.taskItemSelected.description;
Object property shorthand enables us to simply pass in the name of the key as opposed to repeating the name and the key.
Use a for..in loop to clear an object and delete all its properties. The loop will iterate over all the enumerable properties in the object. On each iteration, use the delete operator to delete the current property.
Use Object. Object. keys will return an array, which contains the property names of the object. If the length of the array is 0 , then we know that the object is empty.
Checking empty object with JavaScript It will return false and not throw a TypeError .
Wouldn't that work?
Core.registry.taskItemSelected = {
id: null,
name: null,
parent: null,
...
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With