Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6601199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:43:19+00:00 2026-05-25T18:43:19+00:00

I can’t understand how to get the google closure compiler for javascript to properly

  • 0

I can’t understand how to get the google closure compiler for javascript to properly recognize properties of a constructor. For example, in the code below, I don’t know what type to give ‘cls’ in line 27 so that the compiler does NOT produce the following (erroneous in my opinion) error:

foo.js:29: WARNING – Property say never defined on cls
cls.say();
^

From reading the documentation it seems that I should be doing it as I do in 25. Can someone help please? Thanks,

 1  /**
 2   * @interface
 3   **/
 4  function Sayer() {}
 5  Sayer.prototype.say = function() {};
 6  Sayer.say = function() {};
 7  
 8  /**
 9   * @constructor
10   * @implements {Sayer}
11   **/
12  function A() {}
13  A.say = function() { console.log('A factory'); };
14  A.prototype.say = function() { console.log('Am an A'); }
15  
16  /**
17   * @constructor
18   * @implements {Sayer}
19   **/
20  function B() {}
21  B.say = function() { console.log('B factory'); };
22  B.prototype.say = function() { console.log('Am an B'); };
23  
24  /**
25   * @param {function(new:Sayer)} cls
26   **/
27  function makeSayer(cls) {
28      var obj = new cls();
29      cls.say();
30      obj.say();
31  }
32  
33  makeSayer(A);
34  makeSayer(B);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:43:20+00:00Added an answer on May 25, 2026 at 6:43 pm

    “Sayer.say” on the interfaces is ignored.

    Are you trying to prepare this for Closure’s advanced mode? In advanced mode “A.say” and “B.say” are renamed to “A$say” and “B$say”, the type check expects this and complains about it appropriately (there won’t be a method A.say).

    You can avoid collapsing by have it added by it indirectly:

    function addSay(sayer, fn) {
      sayer.say = fn;
    }
    

    I suppose you could avoid the type warning by adding a line like:

    Function.prototype.say;
    

    But I’m not sure you this is what you want.

    You can avoid the hassle and add it to the prototype and call that instead:

    A.prototype.classSay = function () {};  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can i get the source code for a WAMP stack installer somewhere? Any help
Can I get a 'when to use' for these and others? <% %> <%#
Can anyone give me an example of how to return the following json simply
Can anybody shed some light on getDay() in Javascript please. Here datepicker is textbox
Can we close all known/unknown connections to database with the code? I'm using Access
Can't seem to get the Back Button to appear in a UINavigationController flow. I
Does anyone know how can I replace this 2 symbol below from the string
Can someone explain dependency injection with a basic .NET example and provide a few
can you show me how to assign css properties to the button that is
Can anyone can confirm the best idea for storing jquery code, initially i was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.