-1

I came across some JavaScript syntax I haven't seen before. Can someone help point me in the right direction, I'm not even sure what I could google to learn more :/

$.variable = function() {
  return a(b, [{
    key: "setPeriod",
    value: function(t) {
      this.variable.period = t;
    }
  }, {
    key: "location",
    get: function() {
      return "earth";
    }
  }])
}

$.variable.setPeriod("test");
$.variable.location;

My question is what is this structure where an object is defined via a list. Also not sure what the difference between value and get is. Any help would be appreciated.

Here's an example of a snippet:
https://pastebin.com/zymW2XZw

9
  • Looks like a pair of brackets - () - is missing. Did you copy-paste ? Commented Dec 9, 2017 at 5:23
  • By the way could you include the definition of a and b please ? Commented Dec 9, 2017 at 5:28
  • It's not a copy/paste, i tried to show a simplified version of what was going on. I've included a snippet of the code I was looking at in the original question. Commented Dec 9, 2017 at 5:30
  • Could you share the line number please ? x-D Commented Dec 9, 2017 at 5:32
  • On line 13 you can seen the return statement which returns the output of the function s which includes an array of objects all of which include the key and value fields. Commented Dec 9, 2017 at 5:33

1 Answer 1

1

Here my guess about what happens to this list of objects :

var o = s([{
  key: "attribute",
  value: "default"
}, {
  key: "getAttribute",
  value: function () {
    return this.attribute;
  }
}, {
  key: "setAttribute",
  value: function (value) {
    this.attribute = value;
  }
}]);

console.log(o.getAttribute());
o.setAttribute("custom");
console.log(o.getAttribute());

function s (members) {
  var o = {};
  members.forEach(function (member) {
    o[member.key] = member.value;
  });
  return o;
}

I guess the framework needs to preprocess the object's members for some obscure reasons related to the framework internal mecanism.

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

2 Comments

Hey @leaf thanks for the patience. This question was kind of a shot in the dark. I was hoping someone would recognize what's going on here and shed some light on it. It's difficult to find the functions that are doing the transformations because it was minified and all the functions and variables were renamed and were often reused depending on the context. I appreciate the guess. Especially because it works, I'm accepting this answer. Thanks again.
You're welcome @Rawr, ask if you have more questions :-)

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.