In $.extend(true, {}, obj) in javascript, what is the purpose of 'true'?

Viewed 2745

When comparing the two constructors:

  function C(options, id) {
    this.id = id;

    // Extend defaults with provided options
    this.options = $.extend(true, {}, {
      greeting: 'Hello world!',
      image: null
    }, options);


  };

and

  function C(params, id) {
    this.$ = $(this);
    this.id = id;

    // Extend defaults with provided options
    this.params = $.extend({}, {
      taskDescription: '',
      solutionLabel: 'Click to see the answer.',
      solutionImage: null,
      solutionText: ''
    }, params);
  }

Is the true variable necessary after $.extends?

Secondly, is the statement this.$ = $(this) necessary as the first constructor does not have it and they do the same thing.

1 Answers
Related