我应该使用Meteor.startup()还是$(function(){}) [英] Should I use Meteor.startup() or $(function() {})

查看:64
本文介绍了我应该使用Meteor.startup()还是$(function(){})的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

他们做同样的事情吗?

我应该在客户端内部使用哪个?

Which one should I use inside client?

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

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

推荐答案

据我所知,Meteor.startup(在客户端上)与jQuery的$函数非常相似.使用它的主要优点是,它在客户端和服务器上具有相同的API,因此,如果要在同时在客户端和服务器上运行的文件中编写启动代码,Meteor.startup就可以正常工作. (此外,我个人认为Meteor.startup$更易于阅读和自我记录.)

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 $.)

这篇关于我应该使用Meteor.startup()还是$(function(){})的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆