网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
01月01日漏签0天
javascript吧 关注:269,158贴子:906,476
  • 看贴

  • 图片

  • 吧主推荐

  • 游戏

  • 首页 上一页 1 2 3 4 5 6 7 8 下一页 尾页
  • 143回复贴,共8页
  • ,跳到 页  
<<返回javascript吧
>0< 加载中...

回复:去面试惨败归来,几道题

  • 只看楼主
  • 收藏

  • 回复
  • 野昊
  • for
    8
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
这是哪里的面试题啊?


  • _挑战头巾
  • ifelse
    5
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
一眼看上去 会个4 5道 表示压力很大


2026-01-01 20:18:28
广告
不感兴趣
开通SVIP免广告
  • 血丶好甜
  • ifelse
    5
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
新人根本不知道什么叫做跨域 .. 才学一个星期 = =#


  • 孝诚乐恒
  • ifelse
    5
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼


  • 广播剧社江滨柳
  • switch
    6
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
1、用正则表达式实现字符串首尾空格删除功能
/^ +| +$/g
示例代码:



  • 广播剧社江滨柳
  • switch
    6
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
2、Array(6).join('a');
var a = Array(6,2) // ==> [6,2]
a.length // ==> 2
var a = Array(6) // ==> [undefined, undefined, undefined, undefined, undefined, undefined] // 这个数组的长度为6
a.length // ==> 6
Array(6).join('a') // ==> "aaaaaa"



  • 广播剧社江滨柳
  • switch
    6
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
3、123456['toString']['length'];
函数原型(也就是声明时的样子)的参数的个数,可以由函数对象的length属性获得. (还有个事情, 大家应该都知道: 在函数内部可以使用arguments对象的length属性获得实际参数的个数) 如下所示
function foo(x, y) {
console.log(arguments.length);
}
console.log(foo.length); // ==> 2
foo(1,2,3); // ==> 3
说到argument又想多说一句. argument还有一个属性, callee, 指向正在调用的函数自身. 因此你可以写一些非常蛋疼的函数, 比如斐波那契数列的函数:
(function (x) { return (x==1 || x == 2)? 1 : arguments.callee(x-1)+arguments.callee(x-2); })(6) // ==> 8
Number(12345).toString() // ==> "12345"
toString() 是Object对象的内置函数, 会返回这个对象的字符串形式.
123456['toString']会返回这个函数本身. 而这个函数的原型是:
toString(radix)
其中radix是基数, 默认是10.
因此123456['toString']['length'] 的值是1
但如果不是number对象, 如果是其他内置类型, 比如true['toString']['length'], 答案将是0


  • Apollyonx
  • trycatch
    9
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
一个也不会做。


2026-01-01 20:12:28
广告
不感兴趣
开通SVIP免广告
  • 广播剧社江滨柳
  • switch
    6
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
4、{}+'a'<{}+'b'; [未解决]
(以下我要说的连我自己也弄不清楚是否正确)
要解释清楚这个表达式, 我们一步步来.
{}+'a' // ==> NaN
为什么一个空对象和一个字符串相加返回一个
首先看二元运算符+的解释:
1. Let lref be the result of evaluating AdditiveExpression.2. Let lval be GetValue(lref).3. Let rref be the result of evaluating MultiplicativeExpression.4. Let rval be GetValue(rref).5. Let lprim be ToPrimitive(lval).6. Let rprim be ToPrimitive(rval).7. If Type(lprim) is String or Type(rprim) is String, thena. Return the String that is the result of concatenating ToString( lprim) followed by ToString(rprim)8. Return the result of applying the addition operation to ToNumber( lprim) and ToNumber(rprim). See theNote below 11.6.3.NOTE 1No hint is provided in the calls to ToPrimitive in steps 5 and 6. All native ECMAScript objects except Dateobjects handle the absence of a hint as if the hint Number were given; Date objects handle the absence of a hint as if thehint String were given. Host objects may handle the absence of a hint in some other manner.NOTE 2Step 7 differs from step 3 of the comparison algorithm for the relational operators (11.8.5), by using thelogical-or operation instead of the logical-and operation.
我们直接跳到第5, 6步. 要对参与运算的参数都调用ToPrimitive()方法(而且根据NOTE 1, 这个方法是无参调用). 我们来看一下这个方法:
ToPrimitiveThe abstract operation ToPrimitive takes an input argument and an optional argument PreferredType. Theabstract operation ToPrimitive converts its input argument to a non-Object type. If an object is capable ofconverting to more than one primitive type, it may use the optional hint PreferredType to favour that type.
对于 Object来说
Object Return a default value for the Object. The default value of an object isretrieved by calling the [[DefaultValue]] internal method of the object,passing the optional hint PreferredType. The behaviour of the[[DefaultValue]] internal method is defined by this specification for all nativeECMAScript objects in 8.12.8.
就是要想知道ToPrimitive({})的值,请用DefaultValue内部方法转换之. 来看一下(我偷懒,没转换格式):
8.12.8 [[DefaultValue]] (hint)When the [[DefaultValue]] internal method of O is called with hint String, the following steps are taken:1.2.3.4.5.Let toString be the result of calling the [[Get]] internal method of object O with argument "toString".If IsCallable(toString) is true then,a. Let str be the result of calling the [[Call]] internal method of toString, with O as the this value andan empty argument list.b. If str is a primitive value, return str.Let valueOf be the result of calling the [[Get]] internal method of object O with argument "valueOf".If IsCallable(valueOf) is true then,a. Let val be the result of calling the [[Call]] internal method of valueOf, with O as the this value andan empty argument list.b. If val is a primitive value, return val.Throw a TypeError exception.When the [[DefaultValue]] internal method of O is called with hint Number, the following steps are taken:1.2.3.4.5.Let valueOf be the result of calling the [[Get]] internal method of object O with argument "valueOf".If IsCallable(valueOf) is true then,a. Let val be the result of calling the [[Call]] internal method of valueOf, with O as the this value andan empty argument list.b. If val is a primitive value, return val.Let toString be the result of calling the [[Get]] internal method of object O with argument "toString".If IsCallable(toString) is true then,a. Let str be the result of calling the [[Call]] internal method of toString, with O as the this value andan empty argument list.b. If str is a primitive value, return str.Throw a TypeError exception.When the [[DefaultValue]] internal method of O is called with no hint, then it behaves as if the hint wereNumber, unless O is a Date object (see 15.9.6), in which case it behaves as if the hint were String.The above specification of [[DefaultValue]] for native objects can return only primitive values. If a host objectimplements its own [[DefaultValue]] internal method, it must ensure that its [[DefaultValue]] internal methodcan return only primitive values.
简而言之,无参的DefaultValue会优先调用valueOf()方法, 看看是不是primitive value, 不是的话, 再调用toString()方法.
这个我们熟悉对吧.
({}).valueOf() // ==> Object {}
({}).toString() // ==> "[object Object]"
好了,我们终于把表达式{}+'a'进行了第一步转换:
({}) + 'a' // ==> "[object Object]a"
但 {}+'a'的值是多少呢? 是NaN, 为什么呢? 我也不知道


  • 广播剧社江滨柳
  • switch
    6
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
5、var arr = [1,2,3,4,5,6];arr.splice(1,3);arr.toString();
var arr = [1,2,3,4,5,6];
arr.splice(1,3); // arr ==> [1, 5, 6]
arr.toString(); // ==> "1,5,6"


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 首页 上一页 1 2 3 4 5 6 下一页 尾页
  • 143回复贴,共8页
  • ,跳到 页  
<<返回javascript吧
分享到:
©2026 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示