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?

emrys57
  • 6,679
  • 3
  • 39
  • 49
  • 1
    Digits are legal in JavaScript property names so also in binding handler names. Only the Netbeans checker is overenthusiastic. – nemesv Oct 28 '13 at 14:01

1 Answers1

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;
nemesv
  • 138,284
  • 16
  • 416
  • 359
  • Thanks very much for confirming my suspicions. I submitted a bug report: https://netbeans.org/bugzilla/show_bug.cgi?id=237736 – emrys57 Oct 29 '13 at 08:32