1

My media host is using JSONP to embed videos. I embed this script, along with a few others, in order to embed videos. My understanding is that it's using JSONP in order to overcome CORS issues.

What I do not understand is the last line of the script.

window['wistiajsonp-/embed/medias/8up1lc9606.jsonp'] = window['wistiajsonp-/embed/medias/8up1lc9606.jsonp'];

window['wistiajsonp-/embed/medias/8up1lc9606.jsonp'] = {
    "media": {
        "assets": [{
            "type": "original",
            "slug": "original",
            "display_name": "Original file",
            "width": 1920,
            "height": 1080,
            "ext": "mp4",
            "size": 109515791,
            "bitrate": 16127,
            "public": true,
            "status": 2,
            "progress": 1.0,
            "url": "https://embed-ssl.wistia.com/deliveries/9b53a11c8a871733aadd479d26a10d4555de2d66.bin",
            "created_at": 1522785172
        }, {
            "type": "still_image",
            "slug": "still_image_1920x1080",
            "display_name": "Image",
            "width": 1920,
            "height": 1080,
            "ext": "jpg",
            "size": 216848,
            "bitrate": 0,
            "public": true,
            "status": 2,
            "progress": 1.0,
            "url": "https://embed-ssl.wistia.com/deliveries/bf2cc0bf9de369545df9c9fa8be8371ab8b12f56.bin",
            "created_at": 1522785744
        }],
    "options": {}
};
window['wistiajsonp-/embed/medias/8up1lc9606.jsonp'] = window['wistiajsonp-/embed/medias/8up1lc9606.jsonp'];

(Redacted for the sake of brevity)

Regarding the linked question: I am not talking about Swift; I am talking about JavaScript. Secondly, what I'm asking is directed at the purpose, not the implementation of such "self-assignment".

Daniel Node.js
  • 6,734
  • 9
  • 35
  • 57
  • 1
    In your exemple, no point at all. Usually it's used to keep previously defined value instead of initializing it. Code looks like `window.myModule = window.myModule || {};` – Kulvar Apr 03 '18 at 20:45
  • Maybe they used to have an alias, but in your case the alias name has the same value as the original property name. – Bergi Apr 03 '18 at 20:52
  • 1
    You may also have autogenerated code that does not understand certain edge cases and is producing pointless lines like this. They're pointless, but harmless. – Daniel Apr 03 '18 at 20:52
  • That's not JSONP, which requires a callback to enable asynchronous loading. – Bergi Apr 03 '18 at 20:52
  • Possible duplicate of [What if I want to assign a property to itself?](https://stackoverflow.com/questions/31930257/what-if-i-want-to-assign-a-property-to-itself) – mooga Apr 03 '18 at 21:05
  • 1
    @Mooga -- I don't think this is a duplicate-- this one is about JavaScript, your post is about Swift. And the user isn't asking _how_ to assign a property to itself, but _why_ it is happening in the posted code. – Alexander Nied Apr 03 '18 at 21:07

0 Answers0