I'm in the process of converting a classical OOP project to JS. Everything goes well and I just need to know if one of the methods I used has a shorthand/conventional way to achieve the same I did with it.
In my design I needs to create an empty object with a specific prototype. I used an empty dummy function as the constructorsince I needed an empty object. I can't use new Object() since I need to attach a prototype before the creation.
Here is my code:
var baseObj = {name: '', id: 0}
function emptyObj () {
//this is really a dummy
}
emptyObj.prototype = Object.create(baseObj);
myUser = new emptyObj();
Please note that I have to follow this pattern and my project works very well with it. I just want to know if there is a shorthand/conventional method to create an empty object with a prototype.
Please stick to ES5.
if (i==2) { foo = true};can befoo = i ==2;A short hand method for 2 lines of code. It's not about the number of lines. It is about the concept and the quality of your code.