Skip to content

Instantly share code, notes, and snippets.

@sionjlewis
Created Jun 24, 2015
Embed
What would you like to do?
Client-side Development Techniques with CQWP(s) and JavaScript - Part 3/5
var namespace = function (ns_string, obj) {
var parts = ns_string.split('.'),
parent = window,
pl, i;
for (i = 0, pl = parts.length; i < pl; i++) {
parent = parent[parts[i]] = parent[parts[i]] || (i == pl - 1 && obj ? (typeof obj == 'function' ? (obj() || {}) : obj) : {});
}
return parent;
};
namespace("SJLewis.ProductRelationships", function () {
var self = {};
self.productRelationship = function (id, product1, product2) {
this.id = parseInt(id);
this.product1 = parseInt(product1);
this.product2 = parseInt(product2);
}
self.productRelationships = [];
self.doSomeStuff = function () {
var content = '';
$.each(self.productRelationships, function (index, data) {
content += 'Test ' + data.product1 + ' - ' + data.product2 + '</br>';
})
$('#relationshipEditor').html(content);
}
return self;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment