1

I have a code snippet of JavaScript:

mf.profile.push({
 "Site": {
   "Name": "Jack Montana",                  
   "Identity": 61026032,                   
   "Email": "[email protected]",               
   "Phone": "+14155551234",                
   "Gender": "M",                          
  }
});

mf.event.push("Product viewed", {
    "Product name": "Casio Chronograph Watch",
    "Category": "Mens Accessories",
    "Price": 59.99,
    "Date": new Date()
});

Now my question is what does mf.profile.push or mf.event.push signify?

Is mf an object and profile a function? or both are classes and push is a function?

1
  • 1
    All we can say for sure is that mf is an object, that mf.profile and mf.event are objects and that mf.profile.push and mf.profile.push are functions. However, any value that is not a primitive value is an object. Arrays are objects and so are functions. Any of the values that I identifier as "objects" could also be arrays or functions. Commented Oct 3, 2018 at 18:24

1 Answer 1

4

what does mf.profile.push or mf.event.push signify

The mf variable is an Object literal and the profile/event are properties (may of type array) belongs to this object.

The push() is a method that will add the items passed as parameters to those attributes.

Sign up to request clarification or add additional context in comments.

6 Comments

You can't really know whether they are arrays. They could be arbitrary objects.
.push is a method, not a function.
@user3539626 if the answer is what you're looking for Mark it as the correct answer for the future readers.
@vlaz all methods are functions... anyway thanks for your intervention, updated my post...
A method belongs to a class, while functions are not associated with one. So student.doHomework() is a method and doHomework(student) is a function. In JS it happens that all procedures are called functions, so the definition of a method via JS lingo would be property of an object that contains a function definition. However, that shouldn't stop us using correct terminology, for even a property of an object containing a function is still a method. Were we to go that way, then Java wouldn't have any FP paradigms, as there are no functions, just classes with methods.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.