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

Another _.extend Example

Person = function(name)
{
  this.name = "name";
  this.a = function(a)
 
 {console.log(a)
 
 }

 this.a(this.name);
  this.b();
}

_.extend(Person.prototype, {x: function(){console.log(this.name)}, b: function(){console.log("BBBBBBBBBBBBB")}});

const p= new Person("XXXX");
p.x();


the above is valid code so long as a this.name exists in the Person.prototype

the this.b() is also valid code so long as b() is added in later at the _.extend() part.
Comment

PREVIOUS NEXT
Code Example
Javascript :: Example Of _.extend 
Javascript :: string inverter vs property binding in angular 
Javascript :: https://graph.instagram.com/14.0/17841450694979740 
Javascript :: json to css converter 
Javascript :: Include Id In Backbone 
Javascript :: Add Click events to multiple classes. 
Javascript :: santance case in javascript 
Javascript :: unreachable code detected javascript 
Javascript :: stuck at "resvoling packages" 
Javascript :: ipinfo location javascript 
Javascript :: Listen to custom event in Vue js 
Javascript :: List content on thee currentwdr 
Javascript :: dropdown list trigger change with value jquery 
Javascript :: Constructing a URL from component parts and getting the constructed string 
Javascript :: auto scrolling to end scrollview react native 
Javascript :: javascript chicken 
Javascript :: convert h2 to h1 jQuery 
Javascript :: javascript interview questions geeksforgeeks 
Javascript :: jquery to javascript code converter online 
Javascript :: updating a random variable in a function 
Javascript :: how to get mongoose connection status 
Javascript :: find symmetrical difference of arrays 
Javascript :: mongodb-nodejs-driver-deprecationwarning-collection-count-is-deprecated 
Javascript :: extract image in p5.js 
Javascript :: visual studio code shortcut to find file 
Javascript :: angular universal prerender 
Javascript :: filter json array based on multiple arguments including lists 
Javascript :: angularjs Uncaught ReferenceError: myFunction is not defined at HTMLInputElement.onkeyup 
Javascript :: angularjs Ionic styling container 
Javascript :: Using useEffect with async 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =