A
A
Andrey Bely2020-08-29 13:18:11
1C-Bitrix
Andrey Bely, 2020-08-29 13:18:11

How to deal with the javascipt construct in Bitrix?

Good afternoon I'm
just starting to understand javascript and have the following question:
In the sale.order.ajax component, the order_ajax.php file has the following construction:

createBasketItemImg: function (data) {
      if (!data)
        return;
      var logoNode, logotype;
      logoNode = BX.create('DIV', { props: { className: 'bx-soa-item-imgcontainer' } });

      if (data.PREVIEW_PICTURE_SRC && data.PREVIEW_PICTURE_SRC.length)
        logotype = this.getImageSources(data, 'PREVIEW_PICTURE');
      else if (data.DETAIL_PICTURE_SRC && data.DETAIL_PICTURE_SRC.length)
        logotype = this.getImageSources(data, 'DETAIL_PICTURE');

      if (logotype && logotype.src_2x) {
        logoNode.setAttribute('style',
          'background-image: url(' + logotype.src_1x + ');' +
          'background-image: -webkit-image-set(url(' + logotype.src_1x + ') 1x, url(' + logotype.src_2x + ') 2x)'
        );
      }
      else {
        logotype = logotype && logotype.src_1x || this.defaultBasketItemLogo;
        logoNode.setAttribute('style', 'background-image: url(' + logotype + ');');
      }

      if (this.params.HIDE_DETAIL_PAGE_URL !== 'Y' && data.DETAIL_PAGE_URL && data.DETAIL_PAGE_URL.length) {
        logoNode = BX.create('A', {
          props: { href: data.DETAIL_PAGE_URL },
          children: [logoNode]
        });
      }
      return BX.create('DIV', {
        props: { className: 'bx-soa-item-img-block' },
        children: [logoNode]
      });
    },


At the moment, I'm interested in the very first line createBasketItemImg: function (data), if everything is clear to me with the word function (data), then what is createBasketItemImg: , the name of the function, or something else? The fact is that I am currently watching all sorts of training videos on JS, reading the documentation and have not seen such a construction anywhere, please explain ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2020-08-29
@just_guy95

Bitrix has nothing to do with it, and so this piece is taken out of context.
It's most likely just a property of the object :

var obj = {
  foo: 'bar',
  createBasketItemImg: function(data) {...}
}
obj.createBasketItemImg();

But there may be a loop exit mark , which is unlikely.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question