What is the right way to wire together 2 javascript objects?

前端 未结 6 1911
梦如初夏
梦如初夏 2020-12-28 19:34

I\'m currently facing a conundrum: What is the right way to wire together 2 javascript objects?

Imagine an application like a text editor with several different fi

6条回答
  •  太阳男子
    2020-12-28 19:52

    I'll try to take a stab at this, but it will be a little difficult without seeing any actual code. Personally, I've never seen anybody do such a specific attempt at (M)VC with JavaScript or IoC for that matter.

    First of all, what are you going to test with? If you haven't already, check out the YUI Test video which has some good info on unit testing with javascript.

    Secondly, when you say "the best way to wire up that aggregation" I would probably just do it as a setter w/the controller

    // Production
    var cont = new NotebookController();
    cont.setView( new NotebookView() );
    
    // Testing the View
    var cont = new NotebookController();
    cont.setView( new MockNotebookView() );
    
    // Testing the Controller
    var cont = new MockNotebookController();
    cont.setView( new NotebookView() );
    
    // Testing both
    var cont = new MockNotebookController();
    cont.setView( new MockNotebookView() );
    

    But this makes some big assumption on how you've designed your controller and view objects already.

提交回复
热议问题