AtomLinter / linter-jscs

Atom JSCS linter providers
https://atom.io/packages/linter-jscs
69 stars 32 forks source link

JavaScript Objects #441

Closed JordanTheDodger closed 4 years ago

JordanTheDodger commented 4 years ago

Version

4.2.2

The issue is regarding building javascript objects and accessing properties

// Build JavaScript Object

var myDog = {//name,legs,tails and friends are properties of object "myDog"
  name: "Hunter",
  legs: 4,
  tails: 1,
  friends: ['Jordan', 'Sarina'] //getting error here
};

//Accessing object properties

let dogname = myDog.name; //using dot(.) notation
let friends = myDog['friends']; //using bracket notation
let accessObjProUsingVariableName = 'legs';
let dogleg = myDog[accessObjProUsingVariableName]; //using a variable
console.log('Doglegs :- ' + dogleg);

The above code snippet should run without any warnings or errors. Instead, I am getting errors. image The package(linter-jscs) suggests using dot notation instead of brackets or variable for member expressions.

Is this functionality removed in ES6 or I understood the warning incorrectly. I am using linter-jscs and linter-jshint. I used online code editors, pycharm and it works. It would be good if my most fav editor 'Atom' can make it work. Here is one of the online editors that I used to demonstrate testing using object image

I believe this is a serious issue as to do the testing using object then using dot notation the output that I am getting is 'undefined'

var lookup = {
  alpha: 'Adams',
  bravo: 'Boston',
  foxtrot: 'Frank',
};
function checkObj(checkProp) {
  if (lookup.hasOwnProperty(checkProp)) {
    return lookup.checkProp;
  } else {
    return 'not found';
  }
}

console.log('using object to test' + checkObj('alpha'));

while if you use bracket notation it works. image

Thanks in Advance!!