V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
fantasyni
V2EX  ›  Node.js

bearcat - 让前端也流畅使用依赖注入

  •  
  •   fantasyni · Dec 25, 2014 · 3836 views
    This topic created in 4149 days ago, the information mentioned may be changed or developed.

    bearcat 0.3 版本在圣诞正式推出

    bearcat 不再仅仅支持node.js环境,浏览器环境也完美支持

    意味着 前端也可以编写基于自描述js对象的依赖注入

    依赖关系基于js对象属性的自描述,无需使用require, define来进行模块管理

    同时bearcat还内建了script脚本异步加载机制,无需打包,前端模块化开发所见即所得

    10秒例子,car 依赖 engine,解析到car依赖后,engine就自动加载并注入到car中

    var Car = function() {
    this.$id = "car";
    this.$engine = null;
    }

    Car.prototype.run = function() {
    this.$engine.run();
    console.log('run car...');
    }

    bearcat.module(Car, typeof module !== 'undefined' ? module : {});

    var Engine = function() {
    this.$id = "engine";
    }

    Engine.prototype.run = function() {
    console.log('run engine...');
    }

    bearcat.module(Engine, typeof module !== 'undefined' ? module : {});

    详情还请到官网 http://bearcatjs.org/

    sweet例子 http://bearcatjs.org/examples/

    2 replies    2014-12-25 23:18:49 +08:00
    bolasblack
        1
    bolasblack  
       Dec 25, 2014
    最近从 angularjs 那边确实感受到了依赖注入对测试的帮助,试试你的项目用起来爽不爽
    bolasblack
        2
    bolasblack  
       Dec 25, 2014
    顶上的 GitHub 链接坏掉了, https://github.com/bea**r**catjs/bearcat
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   918 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 55ms · UTC 18:11 · PVG 02:11 · LAX 11:11 · JFK 14:11
    ♥ Do have faith in what you're doing.