Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>AFAIK requirejs isolates loaded libraries to single file. In your page1 and page2 there is no knockout loaded therefore <code>ko</code> namespace is not defined so <code>ko.observables</code> are not defined and when you create new Car it will be undefined. To fix this you should load knockout in page1 and page2 also providing <code>ko</code> namespace as function argument:</p> <pre><code>define(['knockout'], function(ko){ function Car() { var self = this; self.speed = ko.observable(); } }); </code></pre> <p>or using <code>ko = require('knockout');</code> or loading a shim for knockout to be a global namespace</p> <p><strong>EDIT:</strong></p> <p>At least you tried. So here is follow up.</p> <p>When you do define, there is this function you provide with all your view model and other. It is requirejs function and this function should return something (i.e. your viewModel). This way you can have private and public variables and functions inside defined module.</p> <pre><code>define(['knockout'], function(ko){ var Car = function () { var self = this; self.speed = ko.observable(); } return Car; }); </code></pre> <p>The name matters only for this module scope. In your about.js when you import your module you can decide how it will be called:</p> <pre><code>//load page1 script and give returned object //(this case a constructor) name: createCar require(['page1'], function (createCar) { // now create new instance of your Car function: var car = new createCar(); car.speed(60); console.log(car.speed()); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload