By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,948 Members | 1,559 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,948 IT Pros & Developers. It's quick & easy.

Static properties of Class

dmjpro
100+
P: 2,476
Actually a function is treated as a Class in JavaScript.

Expand|Select|Wrap|Line Numbers
  1. function MyClass(){
  2.  
  3. }
  4.  
  5. MyClass.prop = 100;
  6. var mc = new MyClass();
  7.  
Why mc.prop returns undefined?
Apr 2 '09 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
because prop is a member of the MyClass Function object not the MyClass object. when you call the constructor, it executes the function specifyed (MyClass()), this functions returns an empty object.
Apr 2 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.