check方法用于检查参数或类型是否匹配模式。
安装check包
打开命令提示符窗口,并安装该软件包。
C:\Users\Administrator\Desktop\meteorApp>meteor add check

使用check

在我们的下一个例子中,检查 myValue 的值是否是字符串类型。因为它是 true ,应用程序将继续没有任何错误。

meteorApp/client/app.js

var myValue = 'My Value...';
check(myValue, String);
在这个例子中 myValue 的值不是字符串,而是一个数字,以便控制台将记录一个错误。

meteorApp/client/app.js

var myValue = 1;
check(myValue, String);

匹配测试

Match.test 功能类似于 check. 所不同的是在测试失败时,我们将得到控制台错误的值而不会破坏该服务器。下面的例子显示了如何使用多个键进行测试对象。

meteorApp/client/app.js

var myObject = {
key1 : "Value 1...",
key2 : "Value 2..."
} var myTest = Match.test(myObject, {
key1: String,
key2: String
}); if ( myTest ) {
console.log("Test is TRUE...");
} else {
console.log("Test is FALSE...");
}
由于这两个键是字符串,所述测试为真。控制台将记录的第一个选项。
如果我们改变 key2,测试将失败,控制台将记录第二个选项。

meteorApp/client/app.js

var myObject = {
key1 : "Value 1...",
key2 : 1
} var myValue = 1; var myTest = Match.test(myObject, {
key1: String,
key2: String
}); if ( myTest ) {
console.log("Test is TRUE...");
} else {
console.log("Test is FALSE...");
}

Meteor check的更多相关文章

  1. Using View and Data API with Meteor

    By Daniel Du I have been studying Meteor these days, and find that Meteor is really a mind-blowing f ...

  2. Meteor+AngularJS:超快速Web开发

        为了更好地描述Meteor和AngularJS为什么值得一谈,我先从个人角度来回顾一下这三年来WEB开发的变化:     三年前,我已经开始尝试前后端分离,后端使用php的轻量业务逻辑框架.但 ...

  3. meteor报错之:MongoDB had an unspecified uncaught exception.

    今天测试的时候meteor报了个错 如下: MongoDB had an unspecified uncaught exception. This can be caused by MongoDB b ...

  4. Use Node.js DDP Client on Arduino Yun to Access Meteor Server

    Use Node.js DDP Client on Arduino Yun to Access Meteor Server 概述 在Arduino Yun上安装 Node.js, 并測试与 Meteo ...

  5. BFS搜索:POJ No 3669 Meteor Shower

    #include <iostream> #include <cstring> #include <queue> #include <cstdio> #i ...

  6. Meteor ToDo App实例

    在本章中,我们将创建一个简单的待办事项应用程序. 第1步 - 创建应用程序 打开命令提示符,运行以下命令 - C:\Users\Administrator\Desktop>meteor crea ...

  7. POJ3669 Meteor Shower

    http://poj.org/problem?id=3669 类似于迷宫的一道题 但是并没有 给出迷宫具体什么样 但是题目已说在坐标轴的第一象限 然后障碍就是 流星雨所砸范围 安全位置:永远不会发生危 ...

  8. POJ 3669 Meteor Shower BFS求最小时间

    Meteor Shower Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 31358   Accepted: 8064 De ...

  9. 【译】Meteor 新手教程:在排行榜上添加新特性

    原文:http://danneu.com/posts/6-meteor-tutorial-for-fellow-noobs-adding-features-to-the-leaderboard-dem ...

随机推荐

  1. Android(java)学习笔记167:横竖屏切换时Activity的生命周期

    1.横竖屏切换的生命周期     默认情况下横竖屏切换,先销毁再创建 2.有的时候,默认情况下的横竖屏切换(先销毁再创建),对应用户体验是不好的,比如是手机游戏横竖屏切换对游戏体验非常不好,下面两种方 ...

  2. Spread / Rest 操作符

    Spread / Rest 操作符指的是 ...,具体是 Spread 还是 Rest 需要看上下文语境. 当被用于迭代器中时,它是一个 Spread 操作符:(参数为数组) function foo ...

  3. c++:delete或free报错,语法正常。

    #include <stdio.h> #include <iostream> int _tmain(int argc, _TCHAR* argv[]) { ]; memcpy( ...

  4. 雷林鹏分享:Lua 基本语法

    Lua 学习起来非常简单,我们可以创建第一个 Lua 程序! 第一个 Lua 程序 交互式编程 Lua 提供了交互式编程模式.我们可以在命令行中输入程序并立即查看效果. Lua 交互式编程模式可以通过 ...

  5. modify django app models.py adn settings.py

    from django.db import models from django.contrib import admin # from personal import models class Us ...

  6. 手把手入门docker (好多图)

    1.什么是docker? ---->我的理解是将许多应用一起打包成一个镜像,拿这个镜像去其他服务器上运行起来就可以.不需要单个单个去配置啦. 2.怎样在window下的安装. ---->刚 ...

  7. Manjaro安装SS客户端

    首先安装shadowsocks-libev sudo pacman -S shadowsocks-libev 然后编辑配置文件 vim /etc/shadowsocks/config.json { & ...

  8. mysql多字段组合删除重复行

    DELETEFROM boll_paramWHERE id in ( SELECT a.id FROM ( SELECT id FROM boll_param WHERE (symbol, time_ ...

  9. 剑指Offer(书):数值的整数次方

    题目:给定一个double类型的浮点数base和int类型的整数exponent.求base的exponent次方. 分析: * 要注意以下几点:* 1.幂为负数时,base不能为0,不然求的时候是对 ...

  10. POJ 2251-Dungeon Master (三维空间求最短路径)

    Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is co ...