Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

_.extend

/**
* Underscore.js
*
* The _.extend() function is used to create a copy of all of the properties 
* of the source objects over the destination object and 
* return the destination object. 
* The nested arrays or objects will be copied by using reference, not duplicated.
**/
import * as _ from 'underscore'
_.extend(destination, *sources)
Comment

_.extend Example



p = _.extend(Person.prototype, {a:"AAAAAAAA"});
var x =  new p.constructor("some extra stuff");
console.log(x.a);
console.log(x.firstName);
/*has both a="AAAAAAA" and firstName="some extra stuff"*/
/*add stuff to the second, you can think of it as*/
Comment

Example Of _.extend

class Person
{
  constructor(firstName)
  {
    this.firstName = firstName
  }
}


 _.extend(Person.prototype, {addedProperty:"ssssxxxxssss"});

const p = new Person("james");
console.log(p.addedProperty);
Comment

Example Of _.extend


class Person
{
  constructor(firstName)
  {
    this.firstName = firstName
  }
}

class Thing
{
  constructor()
  {
    this.addProperty = "firstName";
  }
}
 

 _.extend(Person.prototype, Thing.property);

const p = new Person("james");
console.log(p.addedProperty);
Comment

Example of _.extend


Person = function(attributes)
{
this.attributes = attributes;
}


_.extend(Person.prototype, {test: function(){return _.clone(this.attributes)}});

const s = new Person("some test text");
 console.log(s.attributes);
 console.log(s.test());
 /*the key to getting attributes to display is using a function(){} and _.clone()*/
/*just test: this.attributes will be undefined*/
Comment

_.extend() Explanation

 var Collection = Backbone.Collection = function(models, options) {
 /**/
    };
    _.extend(Collection.prototype, Events, {...});


/*  h: function(){console.log(this.models);},
so after you use the _.extend, in the third or second {} you want to add to the prototype, any of the inputs parameters of the prototype you can access in the 2nd or 3rd part with this.models 
*/
Comment

PREVIOUS NEXT
Code Example
Javascript :: middleware for angular for passing token in header 
Javascript :: lwc format date js 
Javascript :: onPlay 
Javascript :: santance case in javascript 
Javascript :: How to Solve the Staircase Problem with 5 Lines of JavaScript 
Javascript :: enzyme debounce test 
Javascript :: how can we find location by using date in javascript 
Javascript :: say something in console javascript 
Javascript :: without the filter() method 
Javascript :: cannot read property of undefined js laravel mix 
Javascript :: eva icons js 
Javascript :: get html from url in react js 
Javascript :: load image file input jquery 
Javascript :: filtering to check that a string is contained in the object in js 
Javascript :: node package manager 
Javascript :: javascript splice method 
Javascript :: devexpress image collection 
Javascript :: jquery to javascript code converter online 
Javascript :: javascript detect video change to muted 
Javascript :: Make a Responsive Portfolio Website: JavaScript and HTML 
Javascript :: express check request type 
Javascript :: random color by EventListener click 
Javascript :: Remove special char 4m JS and Join 
Javascript :: angularjs smooth scroll css 
Javascript :: if (arr.indexOf(i) === -1) { return false; 
Javascript :: javascript Why is this function working on second click only 
Javascript :: Setting the default value in the drop down list in AngularJS 
Javascript :: Algolia backend search with Algolia Search Helper library for Angular.js 
Javascript :: Filtering smart-table on transformed data 
Javascript :: Target one specific Jquery Data Table theader for CSS styles 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =