Home >Web Front-end >JS Tutorial >JavaScript advanced learning: first understanding of classes, advanced functions, how to change this pointer
This article brings you relevant knowledge about JavaScript, which mainly introduces the related content of classes, function advancement and how to change this point. I hope it will be helpful to everyone.
[Related recommendations: JavaScript video tutorial, web front-end】
It seems, which one is easier? Yes, it’s the second one (don’t use the bar), this is syntax sugar
2. Array method<script> var arr = [5, 6, 7]; var sum = 0; arr.forEach(function (value, index, array) { console.log(value); sum += value; }) console.log(sum); </script>
// filter var arr1 = [12, 34, 5, 66, 78, 0]; // 由于filter返回的是一个新数组所以需要接收一下newArray var newArray = arr1.filter(function (value, index) { // 找到小于10 的数 return value < 10; }) console.log(newArray);
var arr = [2, 3, 4, 5, 6]; var newArr= arr.some(function (value, index) { return value % 3 === 0; }) console.log(newArr);
Judge in turn, starting from the first element to see if it is satisfied. If the condition does not meet the condition, then search will continue. If the condition is met, it will return true. If no element meets the condition, it will return false
var fileBlog= [ { title: '【JavaScript——初始JS】', url: 'https://blog.csdn.net/zhaochen1127/article/details/125956545?spm=1001.2014.3001.5501', intr: '本文是一篇对js萌新极其友好的一篇文章....' }, { title: '【JavaScript——初始JS】', url: 'https://blog.csdn.net/zhaochen1127/article/details/125956545?spm=1001.2014.3001.5501', intr: '本文是一篇对js萌新极其友好的一篇文章....' }, { title: '【JavaScript——初始JS】', url: 'https://blog.csdn.net/zhaochen1127/article/details/125956545?spm=1001.2014.3001.5501', intr: '本文是一篇对js萌新极其友好的一篇文章....' } ] var fblog = fileBlog.map(function (item) { return ` <li> <h5>${item.title}</h5> <p>${item.intr}</p> <a href="${item.url}" target="_blank">阅读博客</a> </li> ` }) var ul = document.querySelector('.blogs').querySelector('.bcon').querySelector('.blist'); console.log( fblog.join('')); ul.innerHTML = fblog.join('');3. String method
(trim does not affect the string itself, and returns a new string )
trim refers to removing the spaces on both sides and the spaces in the middle of the characters will not be removed
4.Object method Used to obtain all the properties of the object itself object . keys (obj), the effect is similar to for..in, and returns an array composed of property names var obj = {
idcard:10086,
uname:'山鱼',
age:20,
sex:'男'
}
var obj1 = Object.keys(obj);
console.log(obj1);
var obj = { idcard:10086, uname:'山鱼', age:20, sex:'男' } // 给obj添加一个birthday属性,属性值为‘11.27’ Object.defineProperty(obj,'birthday',{ value:'11.27' } ) // 修改obj里面的age属性,修改后的属性值为25 Object.defineProperty(obj,'age',{ value:25 } ) console.log(obj);
(idcard的值并没有修改 )
Object.defineProperty(obj,'location',{ value:'JingXian', writable:false, enumerable:false } ) console.log(obj);
目标属性是否可以被删除或是否可以再次修改特性
Object.defineProperty(obj,'location',{ value:'JingXian', writable:false, enumerable:false, configurable:false } ) delete obj.location; console.log(obj); delete obj.uname; console.log(obj);
也不可以再次修改里面的特性
【相关推荐:JavaScript视频教程、web前端】
The above is the detailed content of JavaScript advanced learning: first understanding of classes, advanced functions, how to change this pointer. For more information, please follow other related articles on the PHP Chinese website!