Reputation: 2224
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
Upvotes: -1
Views: 61
Reputation:
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.
Upvotes: 1