@@ -96,7 +96,7 @@ function completer (text) {
9696
9797 // scope variables
9898 for ( const def in scope ) {
99- if ( scope . hasOwnProperty ( def ) ) {
99+ if ( hasOwnProperty ( scope , def ) ) {
100100 if ( def . indexOf ( keyword ) === 0 ) {
101101 matches . push ( def )
102102 }
@@ -113,7 +113,7 @@ function completer (text) {
113113 // math functions and constants
114114 const ignore = [ 'expr' , 'type' ]
115115 for ( const func in math . expression . mathWithTransform ) {
116- if ( math . expression . mathWithTransform . hasOwnProperty ( func ) ) {
116+ if ( hasOwnProperty ( math . expression . mathWithTransform , func ) ) {
117117 if ( func . indexOf ( keyword ) === 0 && ignore . indexOf ( func ) === - 1 ) {
118118 matches . push ( func )
119119 }
@@ -122,24 +122,24 @@ function completer (text) {
122122
123123 // units
124124 const Unit = math . Unit
125- for ( let name in Unit . UNITS ) {
126- if ( Unit . UNITS . hasOwnProperty ( name ) ) {
125+ for ( const name in Unit . UNITS ) {
126+ if ( hasOwnProperty ( Unit . UNITS , name ) ) {
127127 if ( name . indexOf ( keyword ) === 0 ) {
128128 matches . push ( name )
129129 }
130130 }
131131 }
132- for ( let name in Unit . PREFIXES ) {
133- if ( Unit . PREFIXES . hasOwnProperty ( name ) ) {
132+ for ( const name in Unit . PREFIXES ) {
133+ if ( hasOwnProperty ( Unit . PREFIXES , name ) ) {
134134 const prefixes = Unit . PREFIXES [ name ]
135135 for ( const prefix in prefixes ) {
136- if ( prefixes . hasOwnProperty ( prefix ) ) {
136+ if ( hasOwnProperty ( prefixes , prefix ) ) {
137137 if ( prefix . indexOf ( keyword ) === 0 ) {
138138 matches . push ( prefix )
139139 } else if ( keyword . indexOf ( prefix ) === 0 ) {
140140 const unitKeyword = keyword . substring ( prefix . length )
141141 for ( const n in Unit . UNITS ) {
142- if ( Unit . UNITS . hasOwnProperty ( n ) ) {
142+ if ( hasOwnProperty ( Unit . UNITS , n ) ) {
143143 if ( n . indexOf ( unitKeyword ) === 0 &&
144144 Unit . isValuelessUnit ( prefix + n ) ) {
145145 matches . push ( prefix + n )
@@ -424,3 +424,9 @@ if (version) {
424424 }
425425 } )
426426}
427+
428+ // helper function to safely check whether an object as a property
429+ // copy from the function in object.js which is ES6
430+ function hasOwnProperty ( object , property ) {
431+ return object && Object . hasOwnProperty . call ( object , property )
432+ }
0 commit comments