Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

_.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

Another _extend Example

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

_.extend(Person.prototype, {x: function(){return this.name+"XXXXXXXXX"}});


const p = new Person("John smith");
console.log(p.x());
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 :: _.template Underscore Example 
Javascript :: How to Solve the Staircase Problem with JavaScript using Memoization 
Javascript :: regex to allow spaces and characters 
Javascript :: react native tinder 
Javascript :: how can we find location by using date in javascript 
Javascript :: modify summernote with js 
Javascript :: get data from json key with special character 
Javascript :: telerik mvc grid add row 
Javascript :: react native leaflet 
Javascript :: convert javascript to java 
Javascript :: Argument #1 ($client) must be of type AwsS3Client, AwsS3S3Client given 
Javascript :: regexp look for letter followed by 3 digits 
Javascript :: Minimum Path Sum Rec 
Javascript :: regex from 5 to 30 1 number 1 lower case and 1 upper case letter 
Javascript :: prisma.db firebase 
Javascript :: django ajax json data become string 
Javascript :: fib numbers javascript 
Javascript :: autoplay images in react js 
Javascript :: onScrollBottom 
Javascript :: Check if the same text is repeated javascript todo-app 
Javascript :: node fs get size 
Javascript :: jquery keypress div color change 
Javascript :: copy multi cell value from one sheet to another using google app script 
Javascript :: node js rest with flutter 
Javascript :: js point in rect 
Javascript :: { "typeof": false } 
Javascript :: How to add ui-scroll with remote data in angularjs 
Javascript :: Angular.js : recursive call to an $mdDialog controller 
Javascript :: When doing a booking system, where would it be better to do? Back end or front end 
Javascript :: access language in request express 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =