Archive

Calender

«   2019/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          
 
<script type="text/javascript">

( function () { 

function defineGetter ( objTarget, strName, funcGetter ) { 
                var getter = { 
                              enumerable: true 
                            , configurable: true 
                            , writable: true
                            , get: funcGetter 
                }; 

                if ( Object.defineProperty ) { 
                        try { 
                                Object.defineProperty( objTarget, strName, getter ); 
                        } 
                        catch ( error ) { 
                                delete getter.writable; 

                                try {  Object.defineProperty( objTarget, strName, getter );  } 
                                catch ( e ) { 
                                        objGetter.enumerable = false; 
                                        Object.defineProperty( objTarget, strName, getter ); 
                                } 
                        } 
                } 
                else if ( objTarget.__defineGetter__ ) { 
                        objTarget.__defineGetter__( strName, funcGetter ); 
                } 
                else objTarget[ strName ] = funcGetter;
} 

var stringProto = String.prototype; 

var getter = function () {  return this.substr( 0, 1 );  }; 

defineGetter( stringProto, "firstLetter", getter ); 

}()); 

</script>
 
 
<button onclick="testing()"> Click me </button>

<p id="demo"></p>

<script type="text/javascript">

function testing () { 

        var string = "Welcome my blog! ; 

        demo.innerHTML = string.firstLetter; 
} 
</script>
 

0 Comments