DEV Community

Cover image for {} - Object Literals in Javascript

{} - Object Literals in Javascript

imsabir on March 07, 2022

{} is object literal syntax. let say const circle = {}; Above circle is returning an object. Object in Javascript is essentially collection of...
Collapse
 
thumbone profile image
Bernd Wechner • Edited

I think this is more elegant:

const circle = {
    radius: 1,
    location: {
       x: 1,
       y: 1
    },
    draw() {
     console.log('draw');
    }
 };
Enter fullscreen mode Exit fullscreen mode

That is to say, methods are implicitly functions you don't need to declare them thusly (the (...args) suffices for JS to recognize this as a method and not a property) .

Collapse
 
msabir profile image
imsabir • Edited

Yes but depending upon where it invooked there technical terminology changes.Thats all. In global level the are similar

Collapse
 
thumbone profile image
Bernd Wechner

Do you have any examples of such changing terminology?

Thread Thread
 
msabir profile image
imsabir

Iykyk A method is a procedure or function in object-oriented programming. A function is a group of reusable code which can be called anywhere in your program. This is self explanatory. In global level they are similar.

Thread Thread
 
thumbone profile image
Bernd Wechner • Edited

I don't follow, sorry. How is there terminology changing? Nothing BTW is self explanatory, it's all jargon, and to suggest jargon is self explanatory seems puzzling to me.

Generally methods are viewed as functions that belong to an object (most typically a class instance, though in JavaScript and some other contexts the basic class of "object" can be used generically too. I have yet to see any changing terminology here.

And Iykyk seems a meaningless answer to a question IMHO. If it can't be answered, I guess my point stands, that I really don't know what you're talking about when it comes to changing terminology based on where you invoke something. A method remains a method as far as I know and doesn't change names based on context. Being a subset of functions though, methods are functions, but functions not necessarily methods. And a method can thus be supplied in any context that requires a function.

Thread Thread
 
msabir profile image
imsabir • Edited

So do you mean that method is function and functions are method both are same thing???

If you read article, its mentioned that
If a member is

  • function then it refers as method(), so draw is method

If you want to say that method are those functions which we don't declare, then its definitely correct.

I am not getting what else you want to suggest or convey.

Collapse
 
curiousdev profile image
CuriousDev

Thank you, it would be interesting to know, how the function can use one of the properties of the object literal.

Collapse
 
msabir profile image
imsabir

Yes, will give you the example for same soon.

Collapse
 
msabir profile image
imsabir

Stay tune for next update!!