Javascript hasOwnProperty does not work under Google Chrome

Posted by WebRookie on Stack Overflow See other posts from Stack Overflow or by WebRookie
Published on 2010-04-04T10:42:15Z Indexed on 2010/04/04 10:43 UTC
Read the original article Hit count: 229

I am currently working with some help and it has been going well, until this incident.

function runCommand(commandString) { commands = new Object(); commands.clear = function(){ $('#terminal').html('') }

parameters = commandString.split(" "); command = parameters.shift(); if( commands.hasOwnProperty(command)){ commandscommand; } else { $('#terminal').append(command+' command not recognized.'+'
'); } }

The person who was helping me made this function, so I could run the "terminal-like" browsers that I needed to work on.

It works fine when using Firefox, heres an example:

guest@shell:/$ sudo make me sandwich
sudo command not recognized.
guest@shell:/$ clear

*clears*

guest@shell:/$ clear

But under google chrome this happen:

guest@shell:/$ sudo make me sandwich
sudo command not recognized.
guest@shell:/$ clear
clear command not recognized.

I believe that it has something to do with "commands.hasOwnProperty(command)" that is preventing it from working properly.

I am using JQuery the javascript library to build the website, and I need to know how to solve this problem, or an alternative.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about property