6

I am using knockout.js components where Laravel passes configuration information.

The knockout code lists default options, and merges them with the laravel parameters, using ES2015 (new Javascript) e.g:

this.options = {};
const defaults = {
    option1: true,
    option2: false,
    option3: true
};
Object.assign(this.options,defaults,data.options);

Where data.options are the options set in Laravel Blade

Object.assign works fine except <= IE9

So I have to insert code instead of Object.assign:

for (var key in defaults) {
    if (data.options.hasOwnProperty(key)) {
        this.options[key] = data.options[key];
    } else {
        this.options[key] = defaults[key];
    }
}

I would love to kill this old code but still support IE9 using the following NPM Babel transform:

https://www.npmjs.com/package/babel-plugin-transform-object-assign

However Laravel Elixir appears to not have a babel.rc config, so I am unable to get this transform working.

Help appreciated!

brianlmerritt
  • 2,644
  • 1
  • 34
  • 39
  • Would a simple "old fashioned" polyfill help? https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign (bottom of page) – user3297291 Apr 20 '16 at 12:12
  • Thanks - I am really trying to get Laravel Elixir to apply the polyfill / transform for me (so I can also apply other transforms later, if needed). But I could add a polyfill to the app.js if all else fails. – brianlmerritt Apr 20 '16 at 12:33
  • 1
    Which version of Laravel Elixir are you using? Can you post the `gulpfile.js`? – Nick Apr 28 '16 at 13:07

0 Answers0