最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Should I use Meteor.startup() or $(function() {}) - Stack Overflow

programmeradmin2浏览0评论

Do they do the same thing ?

Which one should I use inside client?

if ( Meteor.is_client ) {
    Meteor.startup(function () {
        // my code here
    });
}

or

if ( Meteor.is_client ) {
    $(function() {
        // my code here
    });
}

Do they do the same thing ?

Which one should I use inside client?

if ( Meteor.is_client ) {
    Meteor.startup(function () {
        // my code here
    });
}

or

if ( Meteor.is_client ) {
    $(function() {
        // my code here
    });
}
Share Improve this question edited Jul 20, 2014 at 14:15 Benjamin Crouzier 41.9k48 gold badges177 silver badges239 bronze badges asked Jul 27, 2012 at 2:36 crapthingscrapthings 2,4853 gold badges21 silver badges33 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 14

As far as I can tell, Meteor.startup (on the client) is very similar to jQuery's $ function. The main advantage of using it is that it's the same API on client and server, so if you want to write startup code in files that are run on both client and server, Meteor.startup will just work. (Also, I personally find Meteor.startup to be easier to read and more self-documenting than $.)

I just ran into an issue that $ was called before template rendering so I hade to use Meteor.startup

So I'd say that if you need to work with DOM elements you have to use Meteor.startup (I used it for the jQuery File Upload plugin)

发布评论

评论列表(0)

  1. 暂无评论