I've recently been following some coding tutorials and I've gotten decent in my general JS knowledge (still have a ton to learn of course). On just about every tutorial I follow.. The code contains this or something like it.
initialize: function() {
var self = this;
this.store = new MemoryStore(function() {
self.renderHomeView();
});
Specifically
initialize: function() {
// code in here
}
I honestly just don't know what this is. Sure, I can finish following a tutorial just fine.. However, I want to understand what it is that I'm coding. Not just copy what someone else has written.
I've tried to use google to find out more about this, but I honestly don't have any clue what search terms to use.
Is this a way to declare a function? As in:
functionName: function(){
// code here
}
// vs
function functionName(){
// code here
}
What am I missing? Could someone send me a link to a resource for this?
Thanks, Jay
functionName: function() {
// some code
}
This is declaring an object property called functionName with a value that's an anonymous (unnamed) function. This would only occur within curly braces defining an object literal. It's different from the following, which declares a named function in the current scope, but isn't a property of any object:
function functionName() {
// some code
}
You can learn more about object literals here: MDN Grammar Reference
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