hasOwnProperty的误区
2012-04-01 21:07
197 查看
package { import flash.display.Sprite; public class Test extends Sprite { private var a : Boolean; public var b : Boolean; internal var c:Boolean; private function test1() : void { } public function test2() : void { } internal function test3():void { } public function Test() { super(); trace( this.hasOwnProperty( "a" ));//false trace( this.hasOwnProperty( "b" ));//true trace( this.hasOwnProperty( "c" ));//false trace( this.hasOwnProperty( "test1" ));//false trace( this.hasOwnProperty( "test2" ));//true trace( this.hasOwnProperty( "test3" ));//false } } }
hasOwnProperty只能判断public权限的属性和方法是否存在,非public的属性和方法一律都为false,如果没注意这点,很容易导致动态获取属性或方法时程序出现所谓的bug
本文出自 “finali” 博客,请务必保留此出处http://finally.blog.51cto.com/4483057/823444
相关文章推荐
- JavaScript中typeof,instanceof,hasOwnProperty,in用法区别
- 关于hasOwnProperty的小试验
- javascript中的hasOwnProperty()、propertyIsEnumerable()和isPrototypeOf()
- isPrototypeOf、instanceof、hasOwnProperty函数整理
- object.hasOwnProperty(name)
- Extjs4---Uncaught TypeError: Cannot call method 'hasOwnProperty' of undefined
- JavaScript秘密花园 - hasOwnProperty,Functions,this
- Javascript中的for in循环和hasOwnProperty结合使用
- JS的hasOwnProperty
- 用hasOwnProperty获取对象自身的属性排除原型链
- javascript中的hasOwnProperty和isPrototypeOf
- js的hasownproperty使用示例
- JS中isPrototypeOf 和hasOwnProperty 的区别
- hasOwnProperty,Object.keys(),propertyIsEnumerable,for-in(loop)
- js中的hasOwnProperty()和isPrototypeOf()
- @property @synthesize的含义以及误区。
- 浅谈js使用in和hasOwnProperty获取对象属性的区别
- 属性检测 In,hasOwnPreperty()和propertyIsEnumerable()
- JavaScript hasOwnProperty() 函数实例详解
- javascript caller,callee,call,apply,hasOwnProperty,深拷贝,浅拷贝