debugging - Access global variables from Require.js in the Chrome Developer Console -


i creating asp.net single-page application, , have require.js config file runs on application start, referencing jquery, sammy.js, , knockout.js. have created shims 3 third-party libraries allow me access them on global level:

require.config({     paths: {         "jquery": "/scripts/jquery-2.1.4.min",         "sammy": "/scripts/sammy-0.7.5.min",         "knockout": "/scripts/knockout-3.3.0",         "text": "/scripts/text",         "appvm": "/scripts/app/appviewmodel"     },     shim: {         "jquery": {             exports: "$"         },         "sammy": {             deps: ["jquery"],             exports: "sammy"         },         "knockout": {             deps: ["jquery"],             exports: "ko"         }     },     priority: ["text", "app"], });  define(["knockout", "appvm", "sammy"], function(ko, appvm, sammy) {     var vm = new appvm();     ko.applybindings(vm);      var app = sammy(function() {         this.get("#dashboard", function() {             //dashboard-related logic here         });     });     app.run("#dashboard"); }); 

i able instantiate knockout viewmodel , bind page. however, when try access global variable "ko" knockout debug in chrome developer console, nothing defined.

how can obtain "ko" object debugging in chrome?

you can expose ko object global main function this:

define(["knockout", "appvm", "sammy"], function(ko, appvm, sammy) {     // expose ko global     window.ko = ko;      var vm = new appvm();     ko.applybindings(vm);      var app = sammy(function() {         this.get("#dashboard", function() {             //dashboard-related logic here         });     });     app.run("#dashboard"); }); 

also might want check out framework durandaljs nice framework uses requirejs, knockoutjs , jquery. has own routing capabilities , nice application lifecycle work with.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -