1

I have an application with a custom binding declared like

ko.bindingHandlers.slideContent2 = {
    init: ...,
    update: ...
}

and I use that in my html with (among other things)

<div data-bind="slideContent2: true"></div>

It works and produces no errors. Today I discover that the new knockout.js syntax checker in Netbeans 7.4 thinks that <div data-bind="slideContent2: true"> is in error. It objects to the digit 2. If I remove that, it thinks the name is fine. Looking around web examples, I haven't found an example of a digit used in the name of a custom binding.

Are digits legal in custom binding names? Is the Netbeans checker being overenthusiastic?

4

1 回答 1

1

From the Knockout point of view every valid JavaScript identifier name is a valid custom binding handler name.

So you can have digits in custom binding handlers. For the full identifier name reference you can check: Valid identifier names

However from the Netbeans syntax checker point of view only letters are allowed in custom binding names.

For reference check out the source of KODataBindLexer (I've added some comments)

case IN_KEY:
  if (!Character.isLetter(c)) { // the character 2 is not a letter
      if (c == ':') {
          state = State.AFTER_KEY;
          input.backup(1); //backup the colon
          return tokenFactory.createToken(KODataBindTokenId.KEY);
      } else if (Character.isWhitespace(c)) {
          state = State.WS_AFTER_KEY;
          input.backup(1); //backup the ws
          return tokenFactory.createToken(KODataBindTokenId.KEY);
      } else { // 2 is not a the colon and not a whitespace so it returns Error:
          state = State.INIT;
          return tokenFactory.createToken(KODataBindTokenId.ERROR);
      }
  }
  //stay in IN_KEY
  break;
于 2013-10-28T15:53:19.470 回答