0

Hi all again,
i have read tutorial about javascript classical inheritance Douglas Crockford wrote. But i did an example for the reason practizing as it showed in his page http://www.crockford.com/javascript/inheritance.html
for ex i did the following example.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>

function Parenizor(value) {
    this.setValue(value);
}

Parenizor.method('setValue', function (value) {
    this.value = value;
    return this;
});

Parenizor.method('getValue', function () {
    return this.value;
});

Parenizor.method('toString', function () {
    return '(' + this.getValue() + ')';
});
myParenizor = new Parenizor(0);
myString = myParenizor.toString();
alert(myString);



</script>

</head>

<body>
</body>
</html>

But it doesnt work. it shows an error. maybe wherever i did mistake. If possible please help to find out problem. Thanks inadvance for attention

2
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by azegurb
0

I don't see your function actually being called anywhere.

i called it here like this
from line 24 to 26

myParenizor = new Parenizor(0);
myString = myParenizor.toString();
alert(myString);
0

and where do you call that? I see no 'onClick', no 'onLoad', no jQuery code that's used to call your code when the page loads.

I've never used inheritance in javascript, so I'm not sure what the issue is, but I doubt that code is ran automatically

0

and where do you call that? I see no 'onClick', no 'onLoad', no jQuery code that's used to call your code when the page loads.

I've never used inheritance in javascript, so I'm not sure what the issue is, but I doubt that code is ran automatically

can you show me how to use it? But even if i call it with onclick or smth like that. it will not show anything

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.