设为首页 收藏本站
查看: 694|回复: 0

[经验分享] nodejs v8 实现 ECMA 5 Mozilla 的一些特性

[复制链接]

尚未签到

发表于 2017-2-22 09:13:20 | 显示全部楼层 |阅读模式
  当开发者写浏览器js时,一些很好内置函数有些浏览器实现了有些却没实现,这样导致程序员根本就不用这些函数。
  如果你在玩nodejs,可以确定这的是这些好用的内置函数都被统一的实现,不需要自己一遍一遍自己实现。
  下面的列出一些非常好用的api 片段 ,这些方法在v8里内置实现了。
  注意:v8 实现了ECMA 3 所有规范,但是仅仅实现了ECMA 5规范部分内容
  语法扩展
   
    
var obj = { get a() { return "something" }, set a() { "do nothing" } }

  getter/setter  方法定义
    
Array



  • Array.isArray(array) – 数组判断.

Array.prototype



  • indexOf(value) – Returns the first (least) index of an element within the array equal to the specified value, or -1 if none is found.

  • lastIndexOf(value) – Returns the last (greatest) index of an element within the array equal to the specified value, or -1 if none is found.

  • filter(callback) – Creates a new array with all of the elements of this array for which the provided filtering function returns true.

  • forEach(callback) – Calls a function for each element in the array.

  • every(callback) – Returns true if every element in this array satisfies the provided testing function.

  • map(callback) – Creates a new array with the results of calling a provided function on every element in this array.

  • some(callback) – Returns true if at least one element in this array satisfies the provided testing function.

  • reduce(callback[, initialValue]) – Apply a function simultaneously against two values of the array (from left-to-right) as to reduce it to a single value.

  • reduceRight(callback[, initialValue]) – Apply a function simultaneously against two values of the array (from right-to-left) as to reduce it to a single value.

Date



  • Date.now() – Returns the numeric value corresponding to the current time.

Date.prototype



  • toISOString() -

Object



  • Object.create(proto, props) – Creates a new object whose prototype is the passed in parent object and whose properties are those specified by props.

  • Object.keys(obj) – Returns a list of the ownProperties of an object that are enumerable.

  • Object.defineProperty(obj, prop, desc) – Defines a property on an object with the given descriptor

  • Object.defineProperties(obj, props) – Adds own properties and/or updates the attributes of existing own properties of an object

  • Object.getOwnPropertyNames(obj) – Returns a list of the ownProperties of an object including ones that are not enumerable.

  • Object.getPrototypeOf(obj) – Returns the prototype of an object.

  • Object.getOwnPropertyDescriptor(obj, property) – Returns an object with keys describing the description of a property (value, writable, enumerable, configurable)

  • Object.preventExtensions(obj) – Prevents any new properties from being added to the given object.

  • Object.isExtensible(obj) – Checks if Object.preventExtensions() has been called on this object.

  • Object.seal(obj) – Prevents code from adding or deleting properties, or changing the descriptors of any property on an object. Property values can be changed however.

  • Object.isSealed(obj) – Checks if Object.seal() has been called on this object.

  • Object.freeze(obj) – Same as Object.seal, except property values cannot be changed.

  • Object.isFrozen(obj) – Checks if Object.freeze() has been called on this object.

Object.prototype



  • __defineGetter__(name, callback) – (Mozilla extension, not ECMAScript 5) Associates a function with a property that, when accessed, executes that function and returns its return value.

  • __defineSetter__(name, callback) – (Mozilla extension, not ECMAScript 5) Associates a function with a property that, when set, executes that function which modifies the property.

  • __lookupGetter__(name) – (Mozilla extension, not ECMAScript 5) Returns the function associated with the specified property by thedefineGetter method.

  • __lookupSetter__(name) – (Mozilla extension, not ECMAScript 5) Returns the function associated with the specified property by thedefineSetter method.

  • isPrototypeOf(obj) – (EcmaScript 3 and 5) Returns true if this is a prototype of the passed in object.

Function.prototype



  • bind(thisArg[, arg1[, argN]]) – Sets the value of ‘this’ inside the function to always be the value of thisArg when the function is called. Optionally, function arguments can be specified (arg1, arg2, etc) that will automatically be prepended to the argument list whenever this function is called.

JSON



  • JSON.stringify(obj) – Takes any serializable object and returns the JSON representation as a string.

  • JSON.parse(string) – Takes a well formed JSON string and returns the corresponding JavaScript object.

String.prototype



  • trim() – Trims whitespace from both ends of the string

  • trimRight() – Trims whitespace from the right side of the string

  • trimLeft() – Trims whitespace from the left side of the string

Property Descriptor Defaults



  • value – undefined

  • get – undefined

  • set – undefined

  • writable – false

  • enumerable – false

  • configurable – false

Missing features



  • Object.__noSuchMethod__ (Mozilla extension, not ECMAScript 5)

  • "use strict"; syntax extension (v8 issue)







运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-345486-1-1.html 上篇帖子: 踏上nodejs的不归路——03阶段性胜利 下篇帖子: NODEJS(2)File Upload Sample with routers and handlers
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表