Linked Questions

27 votes
2 answers
4k views

No colon after property name in object declaration, is it valid? [duplicate]

I entered this expression in the Firefox and Chrome Dev Console and I wonder why it is valid JavaScript: var x = { a (b) {} }; console.log(x); x is then set to an object with the property "a" ...
Lacuno's user avatar
  • 464
2 votes
3 answers
5k views

Shorthand for defining function in JavaScript object [duplicate]

Accidentally I written a code like below, var x = {hai:10,test(){ alert("I am alive")}}; x.test(); //alerting the value It is working fine and I wonder how this code is working? since it was ...
Rajaprabhu Aravindasamy's user avatar
0 votes
2 answers
623 views

Braces as an ES6 function declaration statement? [duplicate]

Found this in a tutorial I was going over. It's ES6. I'm just not sure whats exactly going on. Namely , the way the function(?) is being declared with the array. Where is the colon that declares it ...
Dr. Chocolate's user avatar
2 votes
1 answer
737 views

created() {} vs created: function() {} [duplicate]

I've seen some people use created: function() { // code } and also created () { // code } and then a warning in the Vue docs to not do this created: () => { // code } I understand that ...
Kelvin Zhao's user avatar
  • 2,447
0 votes
1 answer
517 views

Does Vue Need The Function Keyword in Computed Properties and Methods? [duplicate]

I see computed properties and methods in the Vue docs like this: export default { computed: { foo: function() { return 'foo'; } }, methods: { bar: function(x) { return 'bar ' + x; } } ...
Muhammad Rehan Saeed's user avatar
0 votes
1 answer
420 views

Weird function definition syntax in JS [duplicate]

I've discovered this piece of code in the Meteor.js tutorial. It's ES2015: Meteor.methods({ 'tasks.insert'(text) { check(text, String); // Make sure the user is logged in before inserting ...
tristantzara's user avatar
  • 6,007
3 votes
2 answers
98 views

What is this 'method-like' syntax in JS object literal [duplicate]

Use ES6 class sugar, we can define function this way: class Foo { constructor(props) {} ... myFn() {} } and in JS object literal, we can define getters and setters like this: foo = { ...
Allen's user avatar
  • 4,879
4 votes
2 answers
102 views

Why does this code run in javascript ? Function inside an object [duplicate]

When i type this code in javascript console, this does not through an error, instead it runs. var a = { b:"123", update(){ console.log("hello"); } } The problem is, update() does not have ...
Hiteshdua1's user avatar
  • 2,286
2 votes
2 answers
80 views

Different ways of declaring a function within a variable [duplicate]

I'm curious about the following two methods of declaring functions within a variable in Javascript. What's the difference between the two function declarations below? Both seem to work. Are there any ...
shaunb's user avatar
  • 45
1 vote
1 answer
301 views

Vue, do I need the colon for all my functions? [duplicate]

In the Vue documentation, the syntax myFunc: function(){...} is often used, for computed or methods. In these places, myFunc(){...} also works. Is there any difference? Is there any reason not to use ...
bbsimonbb's user avatar
  • 29.2k
0 votes
2 answers
86 views

Is this a computed method name in a block declaration - or is it a typo? [duplicate]

I am unable to understand this piece of JavaScript: Template.welcome.events({ 'submit form' (event, template) { event.preventDefault() } }) Is submit form the name of a method, with ...
Aditya M P's user avatar
  • 5,407
3 votes
1 answer
138 views

Javascript syntax []() and ()() [duplicate]

I'm having trouble understanding these javascript syntaxes. In the block of code below, on the second line. The square bracket is quickly followed by a round bracket or parentheses which I suspected ...
Badmus Taofeeq's user avatar
2 votes
3 answers
57 views

Syntax for object methods [duplicate]

I have always defined methods in objects like this: { a: function(par1, par2) { }, } But recently I see this (which I assume is equivalent, but I am not sure): { a(par1, par2) { }, } When has ...
blueFast's user avatar
  • 45k
0 votes
3 answers
189 views

Are the values defined in this JavaScript object actually functions? [duplicate]

I'm new to JavaScript, and after reading "JavaScript The Good Parts" I wanted to code something for fun. I stubled upon this code snipped that I can't understand: const actions = { say(sessionId, ...
G. Kasev's user avatar
3 votes
1 answer
70 views

Is it valid to define function in javascript object without a property name [duplicate]

I had some issues to get a website working in Internet Explorer (IE9) and I found that we have defined a function in a javascript object in the following way: var test = { a : function(){...
Martin Enders's user avatar

15 30 50 per page