Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1569 In an object constructor how can I ensure that the correct parameters have been passed?

You are here: irt.org | FAQ | JavaScript | Object | Q1569 [ previous next ]

You can check the length of the arguments array:

<script language="JavaScript"><!--
function myObjectConstructor() {
   if (arguments.length < 5) {
      alert('Some foolish programmer did not pass 5 arguments to function myObject');
      return;
   }
}

var object1 = new myObjectConstructor(1,2,3,4,5);  // okay
var object2 = new myObjectConstructor(1,2,3,4);    // not okay
//--></script>

©2018 Martin Webb