简体   繁体   English

检查方法返回未定义

[英]Check method is returning undefined

I have read the documentation. 我已经阅读了文档。 and research about some check package tutorial. 并研究一些check package教程。 meteor docs , try to install again the check package atmospherejs , and look its to simple to use it. 流星docs ,尝试再次安装检查软件包alighterjs ,并使其简单易用。 But

everytime I try something like: 每当我尝试类似的东西:

check("this is string",String); //return undefined

var objectTest = { some : 0 };
check(objectTest, Object); //undefined
check(objectTest.some, Number); //undefined

Its always returning undefined and I dont know why, the check function its there if I write on the chrome console check return 它总是返回未定义的,我不知道为什么,如果我在chrome控制台上写check功能, check功能就在那里

function (value, pattern) {                                              // 19
  // Record that check got called, if somebody cared.                            // 20
  //                                                                             // 21
  // We use getOrNullIfOutsideFiber so that it's OK to call check()              // 22
  // from non-Fiber server contexts; the downside is that if you forget to       // 23
  // bindEnvironment on some random callback in your method/publisher,           // 24
  // it might not find the argumentChecker and you'll get an error about         // 25
  // not checking an argument that it looks like you're checking (instead        // 26
  // of just getting a "Node code must run in a Fiber" error).                   // 27
  var argChecker = currentArgumentChecker.getOrNullIfOutsideFiber();             // 28
  if (argChecker)                                                                // 29
    argChecker.checking(value);                                                  // 30
  try {                                                                          // 31
    checkSubtree(value, pattern);                                                // 32
  } catch (err) {                                                                // 33
    if ((err instanceof Match.Error) && err.path)                                // 34
      err.message += " in field " + err.path;                                    // 35
    throw err;                                                                   // 36
  }                                                                              // 37
}

so the function its there but i dont know how to use it... do you have any idea why its returning undefined? 所以功能在那里,但我不知道如何使用它...你知道为什么它返回未定义吗? (btw I google "Meteor check method return undefined" without success) (顺便说一句,我谷歌“流星检查方法返回未定义”没有成功)

thanks for the support. 感谢您的支持。

//Im using iron route if its matter for some reason //Im not using the function inside of Metero.publish or Meteor.methods //如果出于某种原因要使用铁路线//我不使用Metero.publishMeteor.methods内部的函数

check doesn't return anything. check不返回任何内容。 That's why it always seems to be undefined. 这就是为什么它似乎总是未定义的原因。

It throws an exception if the value does not match the pattern. 如果值与模式不匹配,则会引发异常。 If the value matches the pattern, then it doesn't. 如果该值与模式匹配,则不匹配。

So instead of using if (check(...)) { , you would write code like this: 因此,您无需编写if (check(...)) { ,而是编写如下代码:

function sample(name) {
    check(name, String);
    // code down here won't run if name is not a string
    return name.toUpperCase();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM