Constructor functions

Including knockout for each on observable array

by jiggle

HTML

<div >
    <div data-bind="text:currentStory().title"></div>
    <div data-bind="foreach:currentStory().Paragraphs">
        <div data-bind="text:paraId"></div>
        <div data-bind="text:paraText"></div>
    </div>
</div>
<select data-bind="options:storyList,value:currentStory,optionsText:'title'"></select>

JavaScript

// Undefined return value.
        function A() {
            return;
        }
 
        // Reference to instance.
        function B() {
            return( this );
        }
 
        // String return value.
        function C() {
            return( "string" );
        }
 
        // Number retun value.
        function D() {
            return( 123 );
        }
 
        // New object return value.
        function E() {
            return( { foo: "bar" } );
        }
 
        // New array return value.
        function F() {
            return( [ "foo", "bar" ] );
        }
 
        // New instantiation return value.
        function G() {
            return( new A() );
        }
 
        // Native "object" return value -- this one would be the same
        // for Number, Boolean, and String.
        function H() {
            return( new Number( 123 ) );
        }

         function J(storyNum) {
             var j={
                 title:'new story' + storyNum,
                 storyid:storyNum,
                 Paragraphs:ko.observableArray()
             };
            return( j );
        }
 
 
        // -------------------------------------------------- //
        // -------------------------------------------------- //
 
 
        // See what reference we have as a result of instantiation.
        console.log( new A() );
        console.log( new B() );
        console.log( new C() );
        console.log( new D() );
        console.log( new E() );
        console.log( new F() );
        console.log( new G() );
        console.log( new H() );
var story = J(1);
var storyList = ko.observableArray();
console.log('story',story);
storyList.push(story);
var story1 = J(2);
story1.Paragraphs().push({paraId:4,paraText:'the quick brown fox'});
story1.Paragraphs().push({paraId:5,paraText:'the quick brown fox2'});
story1.Paragraphs().push({paraId:6,paraText:'the quick brown...