Questions tagged [object-literal]

JavaScript Object Literal An object literal is a comma separated list of name value pairs wrapped in curly braces. In JavaScript an object literal is defined as follows: var myObject = { sProp: 'some string value', numProp: 2, bProp: false };

object-literal
Filter by
Sorted by
Tagged with
1 vote
1 answer
68 views

Using object literal for prototype classes

I'm writing some JavaScript classes (old school and NOT using ES2015/ES6 and I don't want to use Babel or other transpilers) and I have one that inherits from the other, overriding one of the parent ...
Cameron's user avatar
  • 28.5k
0 votes
1 answer
1k views

Horizontal axis labels not appearing in Google charts when using object literal notation

Link to the website: http://tecnicosolarboat.tecnico.ulisboa.pt/boatdata/graficos.html Then in the first selection box choose "Tensão Bateria" and in the second one choose "5 Horas". As you can see ...
Sebastião's user avatar
0 votes
0 answers
35 views

Object literal expression using this. to access the context of the code's value [duplicate]

I'm going through a course and working through the example on object literal expressions, the example code given 'use strict'; var price = 5.99, quantity = 10; var prod = { price: 7, quantity: 1, ...
Glyn's user avatar
  • 334
1 vote
1 answer
986 views

Comparison between passing an object with a handleEvent property and traditional callback function in addEventListener

I read an article (link) which explains that the seconde argument of addEventListener can be a function or an object implementing handleEvent method. In the But wait there’s more section of this ...
Junlong Wang's user avatar
4 votes
1 answer
14k views

Javascript - SyntaxError: Invalid or unexpected token - while creating object - Invisible character

I was reading the article on Javascript Objects (http://javascriptissexy.com/javascript-objects-in-detail/), so I copy-pasted the following code into my Notepad++ and ran it in Chrome(Version 55.0....
Uros C's user avatar
  • 2,000
2 votes
1 answer
2k views

Getting "Extra args block must be a javascript object literal." error when trying to move a Google Task

I am trying to change the parent of a new Google task created using Google Scripts. Since the parent must be changed using "move," I'm trying the following: var oldtask = Tasks.Tasks.get(...
fleapower's user avatar
1 vote
1 answer
458 views

Javascript: indexOf in object literal notation

I've the following code in my existing project. //selectedColumn is dynamic but will have part of the string if(selectedColumn.indexOf(const.abc) > -1 || selectedColumn.indexOf(const.abcd) > -1)...
Karthik Chintala's user avatar
0 votes
0 answers
11 views

readFile throws error in object literal [duplicate]

I have a simple node.js server/client program, I wanted to change my existing code so that I could use object literals instead of switch statements, this is the code with switch/case which works fine: ...
Behrang Behvandi's user avatar
1 vote
1 answer
572 views

nested literal objects and filtering by lower case

I have a page where I receive query string values like the following: ?Target=Customers&Sector=Private it might also take the same values as small letters, depending on the user. I have the ...
Jacky's user avatar
  • 423
1 vote
1 answer
70 views

Arrow function in object definition

In Javascript Harmony, we can for example do the following: var maths = { sum (...args) { let r = 0; for (let num of args) { r += num; } return r; } }; maths....
Liglo App's user avatar
  • 3,769
1 vote
1 answer
780 views

Delete region using a button on the region itself

I have added a font -awesome button on a region - in order to delete the region; It looks like this: here is the code that I added to the render function in the wavesurfer.regions.js: var ...
Harriet's user avatar
  • 1,673
0 votes
5 answers
93 views

Object.keys is not efficient if key is instance of RegExp

let ob = {}; ob[/\ing?$/] = `I match all strings end with "ing"`; //key is instance of 'RegEXp' ob["/\ing?$/"] = `I am sure it is not same as the above`; //key is instance of 'String' console.log(...
Abdennour TOUMI's user avatar
1 vote
2 answers
99 views

Can't seem to delete element in object literal [duplicate]

I have a JSON object literal from which I'm trying to delete an element (let's say apples). I've tried many things, but I just can't seem to get it to work. var JSON = { "fruits": [{ "...
Brad's user avatar
  • 1,039
8 votes
3 answers
9k views

Typescript object literal "this" keyword

What's the expected behavior when using this inside a function in an object literal? For example, let's say I have a type foo that only has a function named bar and no other property on it. But in the ...
Arvind Venkataraman's user avatar
1 vote
1 answer
3k views

How to add a key/value pair to a JavaScript object in perticular position? [duplicate]

var obj = {key1: value1, key3: value3}; How can I insert new key value pairs {key2: value2} in second position of the object?
Anand Sharma's user avatar
0 votes
2 answers
2k views

Create an audio element and give it properties inside an object literal

I'm trying to get out of bad habits of writing spaghetti code. I found a great tutorial on modular javascript and I'm trying to apply it to a project of mine. I have this: var sfx = {} sfx.mySound1 ...
Johan's user avatar
  • 130
5 votes
6 answers
235 views

Appending to a JS object that is not an array?

I have an object that looks something like this { "_id": "DEADBEEF", "_rev": "2-FEEDME", "name": "Jimmy Strawson", "link": "placeholder.txt", "entries": { "Foo": 0 } } Which is read ...
Hubert S. Cumberdale's user avatar
0 votes
1 answer
116 views

Loop through JavaScript Object but keep key with value

var data = { 2016-09-24: { 0: {amount: 200, id: 2}, 1: {...} }, 2016-09-25: { 0: {amount: 500, id: 8}, 1: {...} } } I want to represent the above data in a view like: "**" ...
Sylar's user avatar
  • 11.8k
2 votes
2 answers
3k views

TypeScript error when accessing property of object literal

I'm a beginner in TypeScript. I had a bit problem when accessing data of an Object. let content:Array<string> = ["I", "am", "a", "beginner"] let data:Object = {a: "foo", b: content} console.log(...
Vien Nguyen's user avatar
2 votes
1 answer
60 views

$scope is not refreshing data inside template after $apply()

angular.module("mobApp.controllers") .controller("ViewPostController",function($scope , $stateParams, Utils, PublishMessageService, $state, $ionicActionSheet, $ionicModal, Constants, ...
Manish Kumar's user avatar
  • 10.4k
0 votes
1 answer
3k views

Laravel and @if statement inside javascript object literal

I hope i wrote it correctly, as i remember when you have an array options in javascript these are called object literals. I have a problem i can't find how to use @if statement in object literal. I ...
lonerunner's user avatar
  • 1,302
1 vote
2 answers
356 views

How to send a JSON request with params in middle of URL

I have been trying to create a node.js json request object. And i need to pass a parameter in middle of url path. I am giving the below however it is not working.. COuld you please help ? var ...
Sourav's user avatar
  • 506
0 votes
1 answer
264 views

Global Object Literals

I created global var in main,like : on mainPage1.js $(#search).click(){ text = "string from main"; openChildWindow(searchwindow.jsp); }); on mainPage2.js $(#search).click(){ text = "string from ...
bumbumpaw's user avatar
  • 2,530
-1 votes
1 answer
365 views

Javascript class constructor with parameter used as key from object literal [duplicate]

Title might be a little confusing, but I have following problem: var propertyList = { type1: {property1: 1}, type2: {property1: 2} } class Test { constructor(typ){ this....
Furman's user avatar
  • 2,215
1 vote
2 answers
2k views

Javascript: How to return or parse an object literal with eval?

I have a little library that takes strings and constructs objects out of them. For example '-key val' creates {"key": "val"}. However I'm trying to extend the syntax of the input string to take simple ...
Aage Torleif's user avatar
  • 1,991
-1 votes
2 answers
111 views

Why does jQuery code not work after organize with object literal?

So I've been trying to organize my jQuery code (which currently has everything in $(document).ready()) by implementing an object literal on the #Menu. But now the event delegation that used to work is ...
14wml's user avatar
  • 4,138
0 votes
4 answers
80 views

How to set default values for named function parameters simulated via object literals in JavaScript?

I'd like to use named parameters (simulated via object literals) in my JavaScript functions for ease of readability. The code I've written works fine when I explicitly pass my parameters, but I'm ...
Sapphireblue's user avatar
-4 votes
1 answer
51 views

Javascript in Object Literal approach difference between calling a method direct and using Object.create?

Suppose this is my object // Object Literal var personObjLit = { firstname : "John", lastname: "Doe", greetFullName : function() { return "personObjLit says: Hello " + this....
Piyush Jain's user avatar
  • 1,966
-3 votes
1 answer
42 views

Add a new property inside object without directly adding it?

I have this code: var a = { b: "Hello", c: "Foo", d: "Bar" }; if(a["b"]) { // this code will add a new property inside the object a } How can I add a new property without directly adding it ...
Mei's user avatar
  • 31
-1 votes
2 answers
91 views

Looping through object literal with nested functions

I'm trying to loop through an object literal and select just one of the keys and return it's value, which will be a function. My problem is, that I can't get the loop to return just one value - it ...
MortiestMorty's user avatar
0 votes
1 answer
57 views

Adding/removing items dynamically from JSON data parse from mySQL Database with Javascript

I have a mysql database with column ID, NAME , TYPE. The database is then parsed in JSON structure as follows [ {id: "1", name: "Snatch", type: "crime"}, {id: "2", name: "Witches of Eastwick",...
newbieprogrammer's user avatar
11 votes
3 answers
4k views

why doesn't 'this' of an arrow function change inside an nested object literal? [duplicate]

I found that 'this' keyword seems always point to global in using arrow function inside a nested object literal. According to other questions, the following snippet can be explained as an arrow ...
jt-wang's user avatar
  • 113
0 votes
1 answer
598 views

How would I set up JQuery into an Object Literal module?

I'm working on understanding the Object Literal design pattern in JS with JQuery. I have the code separated into different modules to lower the number of time the DOM has to be searched and be ...
sayhelloelijah's user avatar
1 vote
3 answers
39 views

Constructing object based on true/false conditions

I am usually constructing objects that do have fields in them or do not have them based on a condition so let data if(something === true) { data = { name: 'String', something: 'Something' ...
Ilja's user avatar
  • 45.3k
3 votes
5 answers
5k views

Javascript - how to bind 'this' inside an ajax call to the object literal

I have an object literal router, containing an ajax call. I want to call other functions this.printMovies() inside the ajax call but this refer to the ajax object. How do I escape it and make this ...
user avatar
1 vote
3 answers
264 views

How are keys in an object literal evaluated?

Here is my function function goldAndSilver(bin) { var gold = bin.gold; var silver = bin.silver; return { gold: gold, silver: silver }; } Why does the first gold reference the name and ...
JonathanMitchell's user avatar
0 votes
4 answers
40 views

Adding additional functions to object literals after it has been created

So I was wondering whether this is the right way to add functions to an object created through object literals. var person = { firstname: "default", lastname: "default", greet: function (...
lonestarz's user avatar
0 votes
2 answers
121 views

JavaScript object - numeric key literal undefined

This snippet of code has the values I list in the comments. var studentid = course.roster[i]; // studentid = 1367 console.log(studentid); // prints 1367 console.log(students[1367]); ...
ThisClark's user avatar
  • 14.6k
0 votes
1 answer
145 views

Storing jQuery objects using Object Literal pattern

Is it possible to store jQuery objects inside Object Literal pattern? In my case inside config. var myApp = { config: { disabledElem: $('.disable') }, init: function () { ...
Runtime Terror's user avatar
36 votes
1 answer
36k views

Arrow Function in Object Literal [duplicate]

I'm trying to figure out why an arrow function in an object literal is called with window as this. Can someone give me some insight? var arrowObject = { name: 'arrowObject', printName: () => { ...
Dennis S's user avatar
  • 859
0 votes
1 answer
42 views

javascript OOP:reach the method inside object

Here is the my question var panel = { _pnlHeaderContainer: $('.panelHeader'), _pnlHeaderString:"", //private method _Write: function (pnlHeaderString) { return this....
stackada's user avatar
  • 414
0 votes
1 answer
1k views

Javascript (Vuejs) object literal, looping

I have an object in vuejs data: { food: { monday: { pizza:1, chips:2, pie:0, }, tuesday: { ...
LeBlaireau's user avatar
  • 17.3k
2 votes
1 answer
151 views

How to pass array in controller class

In my array like this: { "keys": [ "a", "b", "c", "d", "e", "f" ], "data": [ [ "hh", "hh", "jk",...
W. Praneeth Madusanka's user avatar
2 votes
1 answer
83 views

how to filter data in array loop 222

Previously I asked this question, (how to filter data in array loop) but I have some changes in my second array,.. as given below.. In my array is like this, var myColumnDefs = [ {a: "hh", b: "...
W. Praneeth Madusanka's user avatar
3 votes
3 answers
115 views

how to filter data in array loop

In my array is like this, var myColumnDefs = [ {a: "hh", b: "hh", c: "jk", d: "ggh", e: "hvh"}, {a: "dd", b: "gg", d: "nn", e: "rr", f: "jj"},..... ] I want to filter data and insert data ...
W. Praneeth Madusanka's user avatar
0 votes
0 answers
122 views

Javascript - Creating constructor class within object literal

I'm creating a tic-tac-toe game in Javascript for an online course. I'm trying to set up various properties within an object literal I'm calling "Game". However, I know that when I start writing the ...
Nate Kimball's user avatar
2 votes
3 answers
34 views

use variable to create an Object literal, how to get just its value

can you explain why this Object gets both variable/value instead of just its value? var a = 'foo', b = 'bar', obj = {a, b}; expected obj = {'foo' : 'bar'} result obj = {a: "foo", b: "bar"} ...
Daniele's user avatar
  • 829
2 votes
1 answer
2k views

jQuery Object Literal Pattern

In an effort to write cleaner code i have decided to learn some design patterns. I really love the Object Literal Module pattern, but im having a bit of trouble. I have created a lightbox in spaghetti ...
JamJam's user avatar
  • 23
0 votes
1 answer
78 views

$ for jQuery in object literals in Wordpress

I guess this might be a common question, however I can't find the answer. I'm working on the structure of my JS for my custom Wordpress theme. I decided to use The Object Literal, because it seems to ...
Dmitry Gamolin's user avatar
1 vote
2 answers
91 views

check the name of an object literal property

I have a shorthand function for element creation that takes a tag name and an object literal. //create element function $make(tag, parameters) { var o = document.createElement(t); if (p.style)...
Cliff's user avatar
  • 697

1
3 4
5
6 7
12