home ~ previous

jQuery

Jquery is the most popular JS library. You can do lots of cool things with it, like create web sites exactly the same as Flash was creating eons ago.

Extending objects with jQuery

It’s also pretty good at extending objects in Javascript. In fact, I have decided to use jQuery for this instead of underscore.js as  I am more comfortable in how it looks and works.

Simple example

In JSBIN.com, add a Jquery library to the site and add this: Here is the JS to add into JS Bin. The results will output into the console.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var a = {
  name: "Rohan", 
  address: "Cambridge",
  toes: 10
};

var b = {
  name: "Paul", 
  address: "Bristol",
  fingers: 8
};

var c = {
  name: "Tom", 
  address: "Norfolk",
  thumbs: 2,
  toes: 10
};


var d = jQuery.extend({},a, b, c,{
   legs: 2
});

console.log(a.name); 
console.log(a.address); 
console.log(a.toes);

console.log(b.name); 
console.log(b.address); 
console.log(b.fingers);

console.log(c.name); 
console.log(c.address); 
console.log(c.toes);

console.log(d.name); 
console.log(d.fingers); 
console.log(d.legs);

home ~ previous

Rohan Leach .... thoughtful