Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

make property read-only javascript

Object.prototype.makeReadonly = function(property)
{
	var propValue = this['property'];
  	Object.defineProperty(this, property, {
    	value: propValue,
      	writable: false,
    });
};

var obj = {
	testStr: "Hello World!",
};

obj.makeReadonly('testStr');

obj.testStr = "hello world";
console.log(obj.testStr); // outputs "Hello World!"
Comment

PREVIOUS NEXT
Code Example
Javascript :: react chrome extension 
Javascript :: datepicker min max date 
Javascript :: Function Alert,confirm,prompt 
Javascript :: angular ng owl date time custom format 
Javascript :: javascript filter 
Javascript :: Define the constructor property on the Dog prototype. 
Javascript :: javascript get next 15min 
Javascript :: get request with axios 
Javascript :: redux update item in array 
Javascript :: how to auto update package.json 
Javascript :: try...catch...throw javascript 
Javascript :: set selected option jquery 
Javascript :: link tag react 
Javascript :: Check if an array contains a object in javascript 
Javascript :: Uncaught (in promise) cancel 
Javascript :: js store regex in variable and combine 
Javascript :: geojson 
Javascript :: discord js v12 get user tag with id 
Javascript :: post request with headers 
Javascript :: axios data fetch 
Javascript :: Alpinejs notification 
Javascript :: Adding a Method to a JavaScript Object 
Javascript :: use inline and other styles react native 
Javascript :: get only string from html description javascript 
Javascript :: v-for only getting one first value vuejs 
Javascript :: js convert string to date 
Javascript :: js array reverse 
Javascript :: javascript moment 
Javascript :: on scroll call function jquery 
Javascript :: loop through nested json object typescript 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =