Skip to content

Instantly share code, notes, and snippets.

@KyleGobel
Created December 2, 2013 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KyleGobel/7753052 to your computer and use it in GitHub Desktop.
Save KyleGobel/7753052 to your computer and use it in GitHub Desktop.
var self = this;
var uglyVm = {
object1 : ko.observable("hello there"),
object2 : ko.observable(new (function () {
var self = this;
self.subObject1 = ko.observable("goodbye now");
})(self))
};
//should also work the same as this (relatively)
var simpleVm = {
object1 : ko.observable("hello there"),
object2 : {
subObject1 : ko.observable("goodbye now")
}
};
//another way, to seperate them out even farther
//create the subVm seperate, probably as a function returning an object
//with a constructor to just pass your values in
//like:
// new subVm(item1, item2, addressId, "some other property");
var subVm = {
subObject1 : ko.observable("goodbye now")
};
var simplarVm = {
object1: ko.observable("hello there"),
object2: new subVm(/*with arguments of what you needed to fill at runtime */))
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment