# Custom methods n properties

**URL:** <https://forum.kirupa.com/t/custom-methods-n-properties/127898>\
**Category:** Uncategorized\
**Created:** [November 7, 2004, 9:18pm UTC](https://forum.kirupa.com/t/custom-methods-n-properties/127898 "2004-11-07T21:18:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lostchild](https://avatars.discourse-cdn.com/v4/letter/l/e9a140/32.png) [@lostchild](https://forum.kirupa.com/u/lostchild)\
**Post date:** [November 7, 2004, 9:18pm UTC](https://forum.kirupa.com/t/custom-methods-n-properties/127898/1 "2004-11-07T21:18:12Z")

</div>

In AS2 we can not add methods n properties to built-in classes in the way we do in AS1. Like we would -say- write the custom “isNatural” method on the “Math” class as follows :

- The following code is valid in AS1 but not in AS2

```auto

Math.isNatural = function(number)
	   var isNotNegative = ( number>=0)
	   var isInteger = (number%1 == 0) 
	   return isNotNegative && isInteger
} 
// test
trace (Math.isNatural(7))

```

As the “Math class” is static internally. We know why we can not add custom methods n properties to every class, as the way we do in AS1. Later I came up with senocular’ s very nice tutorial on OOP in AS2. And now i know how we can do it in AS2 style in an efficient n organised way.

But i have a problem with the following code. It should not work ! but it does…

- Following code is valid for both in AS1 and AS2.

```auto
 
var newMath = Math
// radian to Degree
newMath.isNatural = function(number)
		var isNotNegative = ( number>=0)
		var isInteger = (number%1 == 0) 
		return isNotNegative && isInteger
} 
// test
trace (newMath.isNatural(7))

```

The problem with this, is : it s workin in AS2. The Compiler refuses to recognize : “Math.isNatural” which is normal and understandable.  
But after we create a variable called “newMath” n assign it the value (the class) “Math”, it does not have a problem with that . ???

Compiler looks for the variable’ s value n finds it as the “Math” class. So i think, still it should warn me with an error that " there s no property called ‘isNatural’ in Math class ".

Am i mistaken somewhere and if so where ?..
