How to use the extend function from underscore

Find comprehensive JavaScript underscore.extend code examples handpicked from public code repositorys.

119
120
121
122
123
124
125
126
127
128
129
130
    return renderedPosts[normalizedFileName(file)] || null;
}


function addRenderedPostToCache(file, postData) {
    //console.log('Adding to cache: ' + normalizedFileName(file));
    renderedPosts[normalizedFileName(file)] = _.extend({ file: normalizedFileName(file), date: new Date() }, postData);


    if (_.size(renderedPosts) > maxCacheSize) {
        var sorted = _.sortBy(renderedPosts, function (post) { return post.date; });
        delete renderedPosts[sorted.first().file];
fork icon54
star icon266
watch icon27

+ 38 other calls in file

357
358
359
360
361
362
363
364
365
366

if (utils.fileExists(dict_path)) {
   var dict_file = JSON.parse(fs.readFileSync(dict_path));
   if (utils.fileExists(user_dict_path)) {
      var user_dict_file = JSON.parse(fs.readFileSync(user_dict_path));
      _.extend(dict_file, user_dict_file);
   }
   res.send(dict_file);
} else {
   res.send({});
fork icon29
star icon68
watch icon15

44
45
46
47
48
49
50
51
52
53
  accelerometer: { mode: 3 },
  gyroscope: { mode: 0 },
  debug: true
};

_.extend(this, defaults, options);

var accelerometerModes = [
  [MPU6050.ACCEL_FS_2, 16384],
  [MPU6050.ACCEL_FS_4, 8192],
fork icon11
star icon12
watch icon4

+ 2 other calls in file

796
797
798
799
800
801
802
803
804
805
    if (this.clock) {
        playerState.clock = this.clock.getState();
    }
    playerState.promptState = promptState;

    return _.extend(playerState, promptState);
}

getTypeValue(cardType) {
    switch (cardType) {
fork icon9
star icon10
watch icon1

574
575
576
577
578
579
580
581
582
583
}
else
    if( crud.type === "sql" )
        opts = _.extend( opts, { getCrud: function _getCrudSql( req ) {
            /* overwrite sql-crud for this very call (bind req) */
            return _.extend( {}, crud, {
                read: function _crudManager_sql_read( key, callback ) {
                    crud.read( { req: req, key: key }, callback );
                }
            });
fork icon3
star icon9
watch icon1

+ 119 other calls in file

47
48
49
50
51
52
53
54
55
56
57
58
exports.get_config = function(env){
	return _.extend(_config['defaults'], _config[env || process.env.NODE_ENV]);
};


exports.configure = function(env, options){
	_config[env] = _.extend({}, _config[env], options);
}


exports.default_route = {controller: undefined, action: undefined}; 

fork icon0
star icon5
watch icon2

+ 7 other calls in file

47
48
49
50
51
52
53
54
55
56
this.after();
this.rendered = true;	
	
var controller = this;
var defaults = {layout: this.layout, status: 200};
var config = _.extend({}, defaults, options);

if(config.json != undefined){
	this.render_json(options);
}
fork icon0
star icon5
watch icon2

+ 19 other calls in file

56
57
58
59
60
61
62
63
64
65
66
}


function route(req, res, next, params){
  var controller = null;
	var defaults = {format: "html"};
	req.params = _.extend(defaults, req.params, params);
	controller = nerd.modules[req.params.controller + "_controller"];
	if(req.params.controller == "application" || controller == undefined){
		res.writeHead(404);
		res.end();
fork icon0
star icon5
watch icon2

+ 5 other calls in file

52
53
54
55
56
57
58
59
60
61
62
63
64


  // Copy the *extend* function used by Backbone's classes
  EA.extend = Backbone.Model.extend;


  // Copy the basic Backbone.Events on to the event aggregator
  _.extend(EA.prototype, Backbone.Events);


  return new EA();
};

fork icon0
star icon3
watch icon2

+ 5 other calls in file

7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
  completedColor: '#C8F2BE'  // base color for permenant features generated from completed measure
};


_.extend(Symbology.prototype, {
  setOptions: function (options) {
    this._options = _.extend({}, Symbology.DEFAULTS, this._options, options);
    return this;
  },
  getSymbol: function (name) {
    var symbols = {
fork icon0
star icon1
watch icon1

+ 7 other calls in file

4
5
6
7
8
9
10
11
12
13
14
15
let createToken, getToken, getValidToken;


module.exports.createToken = createToken = function (tokenData, cb) {
    let newToken = new callbackTokenModel();


    newToken = _.extend(
        newToken,
        _.pick(
            _.omit(tokenData, Utils.nonCloneable),
            _.pickSchema(callbackTokenModel)
fork icon0
star icon2
watch icon0

+ 3 other calls in file

18
19
20
21
22
23
24
25
26
27
}
newOrganization.owner = organization.owner;

newOrganization.description = "";

newOrganization = _.extend(
    newOrganization,
    _.pick(
        _.omit(organization, Utils.nonCloneable),
        _.pickSchema(organizationModel)
fork icon0
star icon2
watch icon0

23
24
25
26
27
28
29
30
31
    newTeam.repoVisibilty = team.repoVisibilty;
}

newTeam.description = "";

newTeam = _.extend(
    newTeam,
    _.pick(_.omit(team, Utils.nonCloneable), _.pickSchema(teamModel))
);
fork icon0
star icon2
watch icon0

27
28
29
30
31
32
33
34
35
    newProject.repoVisibilty = project.repoVisibilty;
}

newProject.description = "";

newProject = _.extend(
    newProject,
    _.pick(_.omit(project, Utils.nonCloneable), _.pickSchema(projectModel))
);
fork icon0
star icon2
watch icon0

2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
const validPaths = _.pickSchema(
    ipModel,
    Utils.nonCloneable.concat(["inputs", "outputs"])
);
const extension = _.pick(ip, validPaths);
newIp = _.extend(newIp, extension);
newIp.title = newIp.title.trim();

version = parseInt(ip.version);
if (isNaN(version)) {
fork icon0
star icon2
watch icon0

+ 19 other calls in file

101
102
103
104
105
106
107
108
109
110
const valid = await user.isValidPassword(password);
if (!valid) {
    return resolve(null);
}
const profile = await user.getProfile();
const merged = _.extend(
    profile.toJSON(),
    _.omit(user.toJSON(), ["password"])
);
return resolve(merged);
fork icon0
star icon2
watch icon0

+ 3 other calls in file

21
22
23
24
25
26
27
28
29
30

run (opts) {
  if (opts === undefined) {
    opts = {}
  }
  this._settings = _.extend(this._defaults, opts)

  this._createProxy()
  this._createServer()
}
fork icon0
star icon2
watch icon6

+ 3 other calls in file

4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
    repoId: repository._id,
    accessLevel,
};
const files = await repository[functionName]();
return res.status(200).json(
    _.extend(
        {
            files,
        },
        metaData
fork icon0
star icon2
watch icon3

+ 17 other calls in file

524
525
526
527
528
529
530
531
532
533
    );
    user.token = token;
    const profile = await User.getUserProfile({
        user: user._id,
    });
    const merged = _.extend(profile.toJSON(), _.omit(user, ["password"]));
    return res.json(merged);
} catch (err) {
    return res.status(500).json(err);
}
fork icon0
star icon2
watch icon3

+ 7 other calls in file

53
54
55
56
57
58
59
60
61
62
// Transform codepoints to hex strings
var codepoints = _.object(_.map(options.codepoints, function(codepoint, name) {
	return [name, codepoint.toString(16)]
}))

return _.extend({
	fontName: options.fontName,
	src: makeSrc(options, urls),
	codepoints: codepoints
}, options.templateOptions)
fork icon0
star icon1
watch icon1